Nano Nano - 5 months ago 37
AngularJS Question

Angular2 $http promises with Promise.all()

I'm triying to implement a simple promise pattern in angular2. The idea is execute a block of code when the two promise get resolved.

The approach is with

and passing there the promises in my service:

predict(data): Promise<any> {
let headers = new Headers({'Content-Type': 'application/json'});
let dataString = JSON.stringify(data);

return this.http
.post(`${this.baseUrl}/predict`, dataString, headers)
(res: Response) => Promise.resolve(res.json())
(err) => Promise.reject(err)
} // predict

And the component controller:

promiseOne = this.apiservice.predict(titleToPredict);
promiseTwo = this.apiservice.predict(secondTitleToPredict);

Promise.all(promiseOne, promiseTwo)
.then(data => console.log(data))
.catch(err => console.log(err));

But TypeScript Returns me
Supplied parameters do not match any signature of call target.

As i know, the methods are promises, so... i can't figure what is the problem.


Should be...

Promise.all([promiseOne, promiseTwo])

... as this method takes one argument - an Iterable (such as an Array).