I am currently watching Angular2 -alpha45.
Due to the CORS problem, I have to make a JSONP-Call. The problem is that the call takes some time, and I don’t know how to wrap the answer in a promise.
I can transfer regular http.get to a promise, but due to CORS, this is not a solution for my needs.
Working example http.get:
import {Jsonp, Http} from 'angular2/http';
this.getPromise().then(result => {
console.dir(result)
});
getPromise(): Promise<Array> {
return this.http
.get('test.json')
.map((res) => {
return res.json()
})
.toPromise();
}
Jsonp does not work:
import {Jsonp, Http} from 'angular2/http';
this.getPromiseJsonp().then(result => {
console.dir(result)
});
getPromiseJsonp(): Promise<Array> {
var url = this.generateJsonpUrlDataGet2('SingleUser', "test", '');
return this.jsonp.request(url).subscribe(res => {
console.dir(res._body);
return res._body;
}).toPromise();
}
Can someone tell me how to wrap a Jsonp call in a promise?
source
share