OnDestroy class

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;

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

  void 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.





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() → void
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 ==(dynamic other) bool
The equality operator. [...]