Lifecycle Hooks

Lifecycle hooks allow executing logic at different stages of a component’s lifecycle.

Snippet:

export class MyComponent implements OnInit { ngOnInit() { console.log("Component Initialized"); } }

Example:

export class MyComponent implements OnDestroy { ngOnDestroy() { console.log("Component Destroyed"); } }