2.0.1 • Published 6 years ago

angular2-take-until-destroy v2.0.1

Weekly downloads
26
License
MIT
Repository
github
Last release
6 years ago

Build Status Awesome

Angular 2+ - Unsubscribe for pros

Declarative way to unsubscribe from observables when the component destroyed

Installation

npm install angular2-take-until-destroy --save

Usage

import { TakeUntilDestroy } from "angular2-take-until-destroy";

@Component({
  selector: 'app-inbox',
  templateUrl: './inbox.component.html'
})
@TakeUntilDestroy
export class InboxComponent implements OnDestroy {
  componentDestroy;
  constructor( ) {
    const timer$ = Observable.interval(1000)
      .takeUntil(this.componentDestroy())
      .subscribe(val => console.log(val))
  }

  // If you work with AOT this method must be present, even if empty! 
  // Otherwise 'ng build --prod' will optimize away any calls to ngOnDestroy, 
  // even if the method is added by the @TakeUntilDestroy decorator
  ngOnDestroy() {
    // You can also do whatever you need here
  }

}
2.0.1

6 years ago

2.0.0

6 years ago

1.0.4

7 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago