Cookies concent notice

This site uses cookies from Google to deliver its services and to analyze traffic.
Learn more
Skip to main content
This site is no longer updated.Head to Angular.devHome
/

This is the archived documentation for Angular v17. Please visit angular.dev to see this page for the current version of Angular.

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

Methods

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

      
      ngOnDestroy(): void
    
Parameters

There are no parameters.

Returns

void

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