Complete the code to import the lifecycle hook interface for Angular components.
import { Component, [1] } from '@angular/core';
The OnInit interface is used to hook into the component initialization lifecycle event.
Complete the code to implement the OnInit lifecycle hook in the component class.
export class MyComponent implements [1] { ngOnInit() { console.log('Component initialized'); } }
Implementing OnInit allows the component to run ngOnInit() when it starts.
Fix the error in the lifecycle hook method name for the AfterContentInit hook.
export class MyComponent implements AfterContentInit { [1]() { console.log('Content initialized'); } }
The correct method name for the AfterContentInit hook is ngAfterContentInit().
Fill both blanks to create a component that logs messages when it initializes and when it is destroyed.
export class LoggerComponent implements [1], [2] { ngOnInit() { console.log('Logger started'); } ngOnDestroy() { console.log('Logger stopped'); } }
Implementing OnInit and OnDestroy allows the component to run code when it starts and when it is removed.
Fill all three blanks to create a component that logs messages during initialization, after view initialization, and on destruction.
export class FullLifecycleComponent implements [1], [2], [3] { ngOnInit() { console.log('Init'); } ngAfterViewInit() { console.log('View initialized'); } ngOnDestroy() { console.log('Destroyed'); } }
This component implements OnInit, AfterViewInit, and OnDestroy to handle key lifecycle events.