Implement to execute ngOnDestroy before your component is destroyed.

ngOnDestroy is invoked as AngularDart is removing the component or directive from the DOM, as either it has been destroyed as a result of a structural directive's request (*ngIf becoming false), or a parent component is being destroyed. ngOnDestroy may be used to cleanup resources such as StreamSubscriptions:

  selector: 'user-panel',
  template: 'Online users: {{count}}',
class UserPanel implements OnInit, OnDestroy {
  StreamSubscription _onlineUserSub;

  int count = 0;

  ngOnInit() {
    _onlineUserSub = onlineUsers.listen((count) => this.count = count);

  ngOnDestroy() {

Warning: As part of crash detection AngularDart may execute ngOnDestroy a second time if part of the application threw an exception during change detection. It is not recommended to set values to null as a result.

Implemented by




hashCode → int
The hash code for this object. [...]
read-only, inherited
runtimeType → Type
A representation of the runtime type of the object.
read-only, inherited


ngOnDestroy() → dynamic
Executed before the directive is removed from the DOM and destroyed. [...]
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
toString() → String
Returns a string representation of this object.


operator ==(other) → bool
The equality operator. [...]