|
Answer» ANGULAR calls the LIFECYCLE hook methods in the following sequence after creating a component/directive in Angular 6 by calling its constructor: - ngOnChanges()
This responds when Angular re-sets data-bound input properties. - ngOnInit()
Used to initialize the directive/component after Angular first displays the data-bound properties while setting the directive/component's input properties. - ngDoCheck()
Called during every change detection run, immediately after ngOnChanges() and ngOnInit() to detect and act upon changes that Angular won’t do on its own - ngAfterContentInit()
Called once after the first ngDoCheck() to respond after Angular projects external content into the component’s/directive’s view - ngAfterContentChecked()
Called after the ngAfterContentInit() and every SUBSEQUENT ngDoCheck() to respond after Angular checks the projected content. - ngAfterViewInit()
Called once after the first ngAfterContentChecked() to respond after Angular VALIDATES the component and it’s child views. - ngAfterViewChecked()
Called after the ngAfterViewInit() and after every subsequent ngAfterContentChecked(). - ngOnDestroy()
Called just before Angular destroys the directive/component to avoid memory leaks by effective cleanup just before destroying the directives. In the Angular 6 interview question, it is highly recommended to answer the question with the correct sequence by explaining every point. Doing this will increase your chance to get hired.
|