Multiple Hooks in Angular
You can set multiple hooks at the same time. Let's see how this is done using the two hooks we've already studied.
We import two interfaces:
import { OnInit, OnDestroy } from '@angular/core';
Let's connect them to the class:
export class UserComponent implements OnInit, OnDestroy {
}
Let's write our two hooks:
export class UserComponent implements OnInit, OnDestroy {
constructor() {
console.log('constructor is started');
}
ngOnInit() {
console.log('onInit is applied');
}
ngOnDestroy() {
console.log('onDestroy is applied');
}
}
Test both hooks on the reactive condition if.
Test both hooks on the reactive loop.