Let's say I have a function like this in a provider:
getAll(): Observable<CarModel[]> {
return this.http.get<CarModel[]>(this.carUrl);
}
And in a component I have a function that uses this function of the provider:
getCars() {
const that = this;
this.carService.getAll().subscribe(function(cars) {
that.factoryService.setCars(cars);
this.unsubscribe();
});
}
Is it okay to replace that with a function that uses the take
operator to avoid having to call unsubscribe()
?
getCars() {
const that = this;
this.carService.getAll().take(1).subscribe(function(cars) {
that.factoryService.setCars(cars);
});
}
I wonder if this can have any unexpected or unwanted behavior when used with Angular's Httpclient's methods? I've never seen the Angular's Httpclient used like that - that's why I'm asking.