how to unsubscribe for an observable

前端 未结 2 1852
星月不相逢
星月不相逢 2021-01-17 04:03

I have an angular application where I am reading a file and processing it and this processing is part of observable. I have a service which returns the observable an (ngbus

2条回答
  •  旧时难觅i
    2021-01-17 04:35

    You must unsubscribe from the subscription, not the observable:

    processItems() {
        const ngbusy = this.myservice.observable.subscribe(items => {
            // perform some business logic 
    
    
            // unsubscribe at some point...
            ngbusy.unsubscribe();
        });
    
        // this will unsubscribe immediately...
        ngbusy.unsubscribe();
    
    }
    

提交回复
热议问题