Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

unsubscribe does not exist on type Observable<>?

Tags:

angular

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
  }
}
like image 781
xaisoft Avatar asked Dec 08 '22 15:12

xaisoft


1 Answers

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(); 
  }
like image 65
Iancovici Avatar answered Dec 10 '22 11:12

Iancovici