3
我想使用RXJS Observable。基本上它工作正常,但我不需要僅僅在observer.next()時作出反應,而且當observer.complete()被調用時。 如何獲得RXJS Observable的OnComplete事件?在我看來,RXJS文檔令人困惑。RXJS Observable doSomething onComplete
export class Service {
myMethod():Observable<any> {
return Observable.create((observer:any) => {
for(let i=0; i<10; i++) {
observer.next(i);
}
if(true==true) {
// this event I need
observer.complete();
} else {
observer.error(xhr.response);
}
}
}
export class Component() {
// constructor etc.
doSome() {
this.service.myMethod()
// Here I would like to get OnComplete event
.catch(this.handleError)
.subscribe((num:any) => {
console.log(num);
});
}
}
這對我有效.finally(()=> this.handleComplete) – jfgrissom