OnDestroy
A lifecycle hook that is called when a directive, pipe, or service is destroyed. Use for any custom cleanup that needs to occur when the instance is destroyed.
interface OnDestroy {
ngOnDestroy(): void
}
See also
Lifecycle Hooks guide
Methods
A callback method that performs custom clean-up, invoked immediately after a directive, pipe, or service instance is destroyed. |
ParametersThere are no parameters. Returns
|
Usage notes
The following snippet shows how a component can implement this interface to define its own custom clean-up method.
@Component({selector: 'my-cmp', template: `...`})
class MyComponent implements OnDestroy {
ngOnDestroy() {
// ...
}
}