I can not understand what the difference between ngOnInit
and ngAfterViewInit
.
I found the only difference between them is @ViewChild
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.
ngAfterViewInit()
is called after a component's view, and its children's views, are created. Its a lifecycle hook that is called after a component's view has been fully initialized.