angular - 什么是数据绑定(bind)属性?

标签 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.

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

最佳答案

当你有一个组件时

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

  ngOnChanges(changes) {
  }

  ngOnInit() {
  }
}

你可以这样使用它

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

这使 name 成为数据绑定(bind)属性。

somePropInParent 的值发生变化时,Angulars 变化检测会更新 name 并调用 ngOnChanges()

在第一次调用 ngOnChanges() 之后,调用一次 ngOnInit(),表示初始绑定(bind) ([name]="somePropInParent") 已解决并应用。

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

关于angular - 什么是数据绑定(bind)属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39367423/

相关文章:

javascript - Angular 4 - 使用异步自定义验证器

css - 更改 Angular 日期选择器 Material 组件的颜色

angular - 访问 Angular 中其他组件的变量

javascript - 当 aot 设置为 true 时,ngClass 和 ngIf 条件无法编译

javascript - Angular 2 中的 UX 效果

angular - 运行 Angular e2e 测试时如何禁用或绕过 MSAL 身份验证?

Angular - 如何正确使用 Services、HttpClient 和 Observables 在我的应用程序中传递对象数组

css - Angular 中带有 mat-table 的 float 水平滚动条

angular - 调用顺序 HTTP 请求 100 次

javascript - console.log 不会在文档滚动到达末尾时触发