NG Interview Set I - Lifecycle Hooks Questions Flashcards
NG Interview Set I - Lifecycle Hooks Questions
1
Q
What is the possible order of lifecycle hooks in Angular?
A
- ngOnChanges, ngOnInit, ngDoCheck, ngAfterContentInit, ngAfterContentChecked, ngAfterViewInit, ngAfterViewChecked, ngOnDestroy
2
Q
When will ngOnInit be called?
A
- Called once, after the first ngOnChanges
3
Q
How would you make use of onNgInit()?
A
- Fetch initial component data (e.g. from server)
4
Q
What would you consider a thing you should be careful doing on onNgInit()?
A
- You cannot expect the component’s children’s data-bound properties to have been checked at this point
5
Q
What is the difference between onNgInit() and constructor() of a component?
A
- A directive’s data-bound input properties are not set until after construction, so that’s one difference