Whenever a component's input is changed, the ngOnChanges
lifecycle hook is triggered. This allows you to execute any other lifecycle hook or function as needed.
ngOnChanges(...args: any[]) {
console.log('onChange fired');
this.ngOnInit();
}
ngOnInit()
{
console.log('ngOnInit fired');
}
UPDATE:
In case you need to invoke the child component's ngOnInit
from the parent component, you can utilize ViewChild
as demonstrated below.
export class Parent{
@ViewChild(child) vc:child;
ngAfterViewInit()
{
console.log("ngAfterInit");
console.log(this.vc.ngOnInit());
}
};
export class child{
ngOnInit()
{
console.log('ngOnInit fired');
}
};