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
This is a good approach using takeuntil and ngUnsubscribe
private ngUnsubscribe: Subject = new Subject();
ngOnInit() {
this.myThingService
.getThings()
.takeUntil(this.ngUnsubscribe)
.subscribe((things) => console.log(things));
/* if using lettable operators in rxjs ^5.5.0
this.myThingService.getThings()
.pipe(takeUntil(this.ngUnsubscribe))
.subscribe(things => console.log(things));
*/
this.myThingService
.getOtherThings()
.takeUntil(this.ngUnsubscribe)
.subscribe((things) => console.log(things));
}
ngOnDestroy() {
this.ngUnsubscribe.next();
this.ngUnsubscribe.complete();
}