What are data related properties?

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

Description

Implement this interface to execute custom initialization logic after your data properties associated with the directive have been initialized.

ngOnInit is called immediately after the data properties associated with the directive were checked for the first time and before any of its children were checked. It is called only once when the directive is instantiated.

I do not understand directive data-bound properties what does this mean?

+5
source share
1 answer

If you have a component

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

you can use it as

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

This makes the name property associated with the data.

When the value of somePropInParent been changed, Angulars changes the name discovery updates and calls ngOnChanges()

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

See https://angular.io/docs/ts/latest/cookbook/component-communication.html for details

+6
source

All Articles