angular – 什么是数据绑定属性?

前端之家收集整理的这篇文章主要介绍了angular – 什么是数据绑定属性?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我试图理解angular2中的OnInit功能并阅读文档:

Description

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

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.

我不明白指令的数据绑定属性是什么意思?

当你有一个组件
@Component({
  selector: 'my-component'
})
class MyComponent {
  @Input() name:string;

  ngOnChanges(changes) {
  }

  ngOnInit() {
  }
}

你可以像使用它一样

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

这使名称成为数据绑定属性.

更改somePropInParent的值时,Angulars更改检测更新名称调用ngOnChanges()

在第一次调用ngOnChanges()之后,调用ngOnInit()一次,以指示解析并应用了初始绑定([name] =“somePropInParent”).

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

原文链接:https://www.f2er.com/angularjs/143329.html

猜你在找的Angularjs相关文章