A. Missing OnDestroy interface in implements clause
B. ngOnInit method name is incorrect
C. ngOnDestroy should not be used here
D. Console.log statements are invalid
Solution
Step 1: Check implemented interfaces
The class implements OnInit but defines ngOnDestroy() without implementing OnDestroy.
Step 2: Understand interface contract
To use ngOnDestroy(), the class should implement OnDestroy interface for clarity and correctness.
Final Answer:
Missing OnDestroy interface in implements clause -> Option A
Quick Check:
Implement interface for each lifecycle hook used [OK]
Hint: Implement interfaces for all lifecycle hooks used [OK]
Common Mistakes:
Ignoring interface implementation for ngOnDestroy
Thinking method names are wrong
Believing console.log is invalid
5. You want to run code after Angular fully initializes the component's view and its child views. Which lifecycle hook should you use, and why?
Choose the correct hook and reason.
hard
A. ngAfterContentInit() because it runs after projected content is initialized.
B. ngOnInit() because it runs after input properties are set.
C. ngDoCheck() because it runs on every change detection cycle.
D. ngAfterViewInit() because it runs after the component's view and child views are initialized.
Solution
Step 1: Identify hook for view initialization
ngAfterViewInit() runs after Angular initializes the component's view and child views.
Step 2: Compare other hooks
ngOnInit() runs earlier, ngAfterContentInit() runs after projected content, and ngDoCheck() runs repeatedly.
Final Answer:
ngAfterViewInit() because it runs after the component's view and child views are initialized. -> Option D
Quick Check:
View init completion = ngAfterViewInit() [OK]
Hint: Use ngAfterViewInit() for post-view initialization code [OK]
Common Mistakes:
Confusing ngAfterContentInit with ngAfterViewInit
Using ngOnInit for view-dependent code
Expecting ngDoCheck to run once
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.