If I call the method that supports the promise, using the support of the ng2 http Observable.toPromise () provider, it works as expected, but when I use it as part of the promise chain, it solves the returned promise before processing then the handler and returns the result.
Any known issues getting Observable.toPromise () to work in promise chains or alternative ways I can check to make it compatible with the promise of the result? I was blocked by this allow promise before the http request, the last element in the promise chain, completed the asynchronous request request and returned the result.
for example
this.myService.getSomethingInvolvingingMultiplePromiseCalls().then(result => {
let valueFromSomethingInvolvingMultiplePromiseCalls = result;
}, err => {
console.error('landed in app.component outer promise rejected handler, see output window for details')
})
public getSomethingInvolvingingMultiplePromiseCalls(): Promise<string> {
return this.getSomethingInvolvingPromiseCall().then(resultPromise1 => {
let resultPromise1propertyFoo = resultPromise1.propertyFoo;
return this.getSomethingInvolvingNg2HttpProviderToPromiseCall(resultPromise1propertyFoo);
}
.then(resultPromise2 => {
let resultPromise2propertyBar = resultPromise2.propertyBar;
return resultPromise2propertyBar;
}
}
getSomethingInvolvingNg2HttpProviderToPromiseCall(arg1: string): Promise<string> {
let body = 'some body content leveraging arg1';
let headers = new Headers({ 'Authorization': 'Bearer ' + accessToken, 'Content-Type': 'application/x-www-form-urlencoded' });
let options = new RequestOptions({ headers: headers });
return this.http.post(resourceBaseAddress + '/someRestApi', body, options).toPromise().then(response => {
let responseJson = response.json();
return responseJson['someJsonProperty'];
});
}
}
in advance in advance for any ideas or suggestions.