We access our CSV data via a Slice Object Store observable like this:
this.s.os.S.CSV_DATA.obs.subscribe(data=>console.log(data))
We want to automatically unsubscribe
when the component is destroyed.
Approach
Use the library @ngneat/until-destroy:
npm i @ngneat/until-destroy
Decorate the component with @UntilDestroy()
:
@UntilDestroy()
@Component({
...
})
And pipe
through untilDestroy
:
this.s.os.S.CSV_DATA.obs.pipe(untilDestroyed(this)).subscribe(...)
The Subscription
instance will now be automatically unsubscribed
.