Complete the code to import the lifecycle hook interface for initialization.
import { Component, [1] } from '@angular/core';
The OnInit interface is used to run code when the component initializes.
Complete the code to implement the lifecycle hook method that runs after component initialization.
export class MyComponent implements OnInit { [1]() { console.log('Component initialized'); } }
The method ngOnInit runs once after the component is created and initialized.
Fix the error in the lifecycle hook method name to correctly detect changes.
export class MyComponent implements DoCheck { [1]() { console.log('Change detected'); } }
The DoCheck interface requires the method ngDoCheck to detect changes manually.
Fill both blanks to create a component that logs messages on initialization and destruction.
export class LoggerComponent implements OnInit, [1] { ngOnInit() { console.log('Logger started'); } [2]() { console.log('Logger stopped'); } }
The component implements OnDestroy and defines ngOnDestroy to run code when the component is removed.
Fill all three blanks to create a component that logs messages on initialization, after view init, and destruction.
export class FullLoggerComponent implements OnInit, AfterViewInit, OnDestroy { [1]() { console.log('Component initialized'); } [2]() { console.log('View initialized'); } [3]() { console.log('Component destroyed'); } }
The methods ngOnInit, ngAfterViewInit, and ngOnDestroy correspond to the lifecycle hooks for initialization, view ready, and cleanup.