npm install ngx-auto-unsubscribe --save
import { AutoUnsubscribe } from "ngx-auto-unsubscribe";
@AutoUnsubscribe()
@Component({
selector: 'inbox'
})
export class InboxComponent {
one: Subscription;
two: Subscription;
constructor( private store: Store<any>, private element : ElementRef ) {}
ngOnInit() {
this.one = store.select("data").subscribe(data => // do something);
this.two = Observable.interval.subscribe(data => // do something);
}
// 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 @AutoUnsubscribe decorator
ngOnDestroy() {
// You can also do whatever you need here
}
}