I need to wait for a promise to complete before activating an observable in Angular 2 with RxJS.
More specifically, I need to set up state using a third party library that returns promises, and insert some resulting information into my HTTP headers before making GET requests:
export class LiveDataService {
private headersPromise;
constructor(public http: Http) {
this.headersPromise = $.connection('/init').then((state) => setupHeaders(state));
}
activate(route: string) {
return this.http.get('api/v1/' + route, { headers })
.Merge(anotherStateBasedObservable);
}
)
Except, although I need to return the observable immediately as shown, I also must wait for the promise to complete before calling the http.get
.
I can think of a couple ways that require like 3-4 stages of translation, but I feel like there should be a fairly direct way to do this.