Reputation: 17214
I want to run first authenticate http get function, once its successful, then run another function and then return back Observable, so it can be subscribe and continue using with other methods.
return new Observable(observer => {
this.api
.login(username, password)
.subscribe(
data => {
this.data = this.dataParse(data);
observer.next(this.data);
observer.complete();
});
// run another http.get to get user profile, before sending back Observable
});
I'm not sure how to run another http.get and then return observable.
I can run another function inside .subscribe() method, but then it wont be linked with current Observable
Upvotes: 2
Views: 745
Reputation: 42669
While I have not tried, you need to pipe the response for the login to a chain of operators. Something along these lines:
return this.api
.login(username, password)
.map((res:Response) => res.json())
.mergeMap(data=> $http.get(data.id));
You do not need to create a new Observable.
Upvotes: 3