什么是数据绑定属性? [英] What is data-bound properties?

查看:138
本文介绍了什么是数据绑定属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图了解angular2中的OnInit功能并阅读文档:

I am trying to understand OnInit functionality in angular2 and read the documentation:

说明

在执行此接口后执行自定义初始化逻辑 您指令的数据绑定属性已初始化.

Implement this interface to execute custom initialization logic after your directive's data-bound properties have been initialized.

ngOnInit 已被第一次检查,并且在其任何子检查之前 已经检查过了.当指令为 实例化.

ngOnInit is called right after the directive's data-bound properties have been checked for the first time, and before any of its children have been checked. It is invoked only once when the directive is instantiated.

我不明白directive's data-bound properties是什么意思?

I do not understand directive's data-bound properties what does it mean?

推荐答案

有组件时

@Component({
  selector: 'my-component'
})
class MyComponent {
  @Input() name:string;

  ngOnChanges(changes) {
  }

  ngOnInit() {
  }
}

您可以像使用它

<my-component [name]="somePropInParent"></my-component>

这使name成为数据绑定属性.

This make name a data-bound property.

更改somePropInParent的值时,Angulars更改检测将更新name并调用ngOnChanges()

When the value of somePropInParent was changed, Angulars change detection updates name and calls ngOnChanges()

第一次调用ngOnChanges()后,ngOnInit()被调用一次,以表示已解析并应用了初始绑定([name]="somePropInParent").

After ngOnChanges() was called the first time, ngOnInit() is called once, to indicate that initial bindings ([name]="somePropInParent") were resolved and applied.

有关更多详细信息,请参见 https://angular.io/docs/ts/latest/cookbook/component-communication.html

For more details see https://angular.io/docs/ts/latest/cookbook/component-communication.html

这篇关于什么是数据绑定属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆