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:

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

  int count = 0;

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

  @override
  ngOnDestroy() {
    _onlineUserSub.cancel();
  }
}

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

Constructors

OnDestroy()

Properties

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

Methods

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. [...]
inherited
toString() → String
Returns a string representation of this object.
inherited

Operators

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