While implementing unsubscrive, I saw this answer.
I am tring the solution mentioned, but wanted to understand the following:
If I 'console.log(this.ngUnsubscribe)' before the 'this.ngUnsubscribe.next()' I see that the observers property of it is an array with 0 items.
Does it make sense? or am I missing something?
(before the subscribe I added the takeUntil(this.ngUnsubscribe) of-course)
----Update - added the code ----
imports:
import "rxjs/add/operator/takeUntil"
import {Subject} from "rxjs/Subject"
class:
export class CarComponent{
@Input() id;
car:Car;
ngUnsubscibe:Subject<boolean> = new Subject();
constructor(private carsService:CarService){}
ngOnInit(){
this.carsService.getDetails(this.id)
.takeUntil(this.ngUnsubscibe)
.subscribe((car) => {this.car = car},
(err) => console.log(err)
);
}
ngOnDestroy(){
//HERE - in the log, the object has property 'observers'
//of type array which the length of it is 0
console.log(this.ngUnsubscibe);
this.ngUnsubscibe.next(true);
this.ngUnsubscibe.complete();
}
}