[ Web Proxy ]
URL:
Viewing: https://angular.dev/api/core/OnDestroy [Back]  [Original]

OnDestroy Angular Skip to main content
menu
close
more_horiz
menuAPI
@angular/core

OnDestroy

interface
stable

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.

Lifecycle hooks guide

On this page

    arrow_upward_alt Back to the top

    API

        
          interface OnDestroy {  ngOnDestroy(): void;}
        
        

    ngOnDestroy

    void

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

    @returnsvoid

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

    Web Proxy Viewer  |  New URL  |  Original Page