Using the RXJS Observable has been smooth sailing so far, but I now find myself needing to not only react to observer.next() but also when observer.complete() is called. How can I capture the OnComplete event of an RXJS Observable? The documentation for RXJS seems unclear on this matter.
export class Service {
myMethod():Observable<any> {
return Observable.create((observer:any) => {
for(let i=0; i<10; i++) {
observer.next(i);
}
if(true==true) {
// It's this event that I require
observer.complete();
} else {
observer.error(xhr.response);
}
}
}
export class Component() {
// constructor etc.
doSome() {
this.service.myMethod()
// Here I want to receive the OnComplete event
.catch(this.handleError)
.subscribe((num:any) => {
console.log(num);
});
}
}