Reputation: 847
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 Promise.all()
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)
.toPromise()
.then(
(res: Response) => Promise.resolve(res.json())
)
.catch(
(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.
Upvotes: 1
Views: 1230
Reputation: 106385
Should be...
Promise.all([promiseOne, promiseTwo])
... as this method takes one argument - an Iterable (such as an Array).
Upvotes: 2