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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

When will ngOnInit be called?

A
  • Called once, after the first ngOnChanges
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How would you make use of onNgInit()?

A
  • Fetch initial component data (e.g. from server)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly