Angular 6 References/ Core


This is the documentation for Angular 6.
You can switch to the latest version Angular 10.

A callback method that performs custom clean-up, invoked immediately after a directive, pipe, or service instance is destroyed.

ngOnDestroy(): void


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() {
    // ...