Loading

Quipoin Menu

Learn • Practice • Grow

angular / Component Lifecycle
mcq
Direction: Choose the correct option

Q1.

Which lifecycle hook is called after the component's constructor?
A. ngOnDestroy
B. ngOnChanges
C. ngOnInit
D. ngAfterViewInit
Direction: Choose the correct option

Q2.

When is `ngOnChanges` called?
A. After content projection
B. After view initialization
C. Before component destruction
D. When any data-bound input property changes
Direction: Choose the correct option

Q3.

Which hook is called once after the component's view has been fully initialized?
A. ngOnInit
B. ngAfterContentInit
C. ngDoCheck
D. ngAfterViewInit
Direction: Choose the correct option

Q4.

What is the purpose of `ngOnDestroy`?
A. Initialize data
B. Update the view
C. Check for changes
D. Clean up resources before the component is destroyed
Direction: Choose the correct option

Q5.

Which hook is called during every change detection run?
A. ngAfterViewChecked
B. All of the above
C. ngOnChanges
D. ngDoCheck
Direction: Choose the correct option

Q6.

What is the order of execution for these hooks: constructor, ngOnChanges, ngOnInit?
A. constructor -> ngOnChanges -> ngOnInit
B. ngOnInit -> constructor -> ngOnChanges
C. constructor -> ngOnInit -> ngOnChanges
D. ngOnChanges -> constructor -> ngOnInit
Direction: Choose the correct option

Q7.

When is `ngAfterContentInit` called?
A. After view initialization
B. After component creation
C. After change detection
D. After content projection into the component
Direction: Choose the correct option

Q8.

What is the difference between `ngAfterViewInit` and `ngAfterViewChecked`?
A. They are the same
B. `ngAfterViewChecked` is called once
C. `ngAfterViewInit` called once, `ngAfterViewChecked` called after every change detection
D. `ngAfterViewInit` called multiple times
Direction: Choose the correct option

Q9.

What should you avoid doing in `ngOnInit`?
A. Subscribing to observables
B. Heavy synchronous operations that delay rendering
C. Initializing properties
D. Calling services
Direction: Choose the correct option

Q10.

Can you implement lifecycle hooks in directives?
A. Only attribute directives
B. Yes, directives also have lifecycle hooks
C. No, only components
D. Only structural directives