I am trying to unsubscribe from an observable in ngOnDestroy, but it is telling me it does not exist on type Observable.
export class AppComponent implements OnInit {
public caseData;
constructor(private _caseService: CaseService,
private _title: Title,
private _metaService: Meta) { }
ngOnInit(): void {
this._caseService.GetCaseData('en', 'English');
this._caseService.caseData$.subscribe(res => { this.caseData = res },
(error) => { console.log(error) });
}
ngOnDestroy() {
this._caseService.caseData$.unsubscribe(); //says it does not exist
}
}
The subscription itself is returned.
subscription: Subscription;
ngOnInit(): void {
this._caseService.GetCaseData('en', 'English');
this.subscription = this._caseService.caseData$.subscribe(res => { this.caseData = res },
(error) => { console.log(error) });
}
ngOnDestroy(){
this.subscription.unsubscribe();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With