OnDestroy class abstract

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
  void ngOnInit() {
    _onlineUserSub = onlineUsers.listen((count) => this.count = count);
  }

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

Implementers

Constructors

OnDestroy()

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

ngOnDestroy() → void
Executed before the directive is removed from the DOM and destroyed.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited