I have a variable to which I assign a subscription to a request, I want to get the last value issued by that subscription. My code is similar to the following
// Service 1
public request
getData() {
return new Observable((observer) => {
if (this.request) this.request.unsubscribe();
this.request = this.http.get(this.requestExploreUrl()).subscribe((data) => {
observer.next(data);
});
});
}
I realize that the code doesn't make much sense, but there are several components that consume this service, is it possible to subscribe to the value of the request variable?
I have tried service1.request.subscribe (x => x) doesnt work
Also you cannot try another service1.getData().subscribe (x => x) because having an if (this.request) this.request.unsubscribe (); the last subscription will be canceled.