Below is the explanination provided for OnChanges life cycle event in angular2 documentation.
ngOnChanges - before ngOnInit and when a data-bound input property value changes.
Below is my sample component code
@Component({
selector:'app-main',
template:`
<user-form>Loading....</user-form>
`,
directives: [userFormComponent],
providers: [HTTP_PROVIDERS,UserService]
})
export class AppComponent implements OnInit , OnChanges {
@Input()
public prop: string = "hi!";
ngOnInit() {
console.log('ngOnInt') ;
}
ngOnChanges() {
console.log('ngOnChanges') ;
}
}
And I am refering to this component in my html page like this
<app-main [prop]="test">Loading...</app-main>
Now my question is, even though I am changing databound input property "prop" by assiging value "test", why is that ngOnChanges is not executed. By the way I am new to angular2.