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))
}
ngOnDestroy() {
}
}