Implement this interface to get notified when your directive is destroyed.

ngOnDestroy callback is typically used for any custom cleanup that needs to occur when the instance is destroyed

Examples

Try this live example from the Lifecycle Hooks page:

// Spy on any element to which it is applied. // Usage: <div mySpy>...</div> @Directive(selector: '[mySpy]') class SpyDirective implements OnInit, OnDestroy { final LoggerService _logger; SpyDirective(this._logger); ngOnInit() => _logIt('onInit'); ngOnDestroy() => _logIt('onDestroy'); _logIt(String msg) => _logger.log('Spy #${_nextId++} $msg'); }

Constructors

OnDestroy()

Properties

hashCode → int

Get a hash code for this object.

read-only, inherited
runtimeType → Type

A representation of the runtime type of the object.

read-only, inherited

Operators

operator ==(other) → bool

The equality operator.

inherited

Methods

ngOnDestroy() → dynamic

noSuchMethod(Invocation invocation) → dynamic

Invoked when a non-existent method or property is accessed.

inherited
toString() → String

Returns a string representation of this object.

inherited