A
A
Alexander Sharomet2017-08-22 20:41:16
JavaScript
Alexander Sharomet, 2017-08-22 20:41:16

Why is there a toPromise method in angular 4?

Hello.
I have a method
getAllUsers(){
return this.http.get('/api/users')
.map(res => res.json());
}
The documentation says that you need to use the Promise method. Why is it needed?
getAllUsers(): Promise {
return this.http.get('/api/users')
.toPromise()
.then(response => response.json().data as User[])
.catch(this.handleError);
}
Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Negwereth, 2017-08-22
@sharomet

Because observable is there by default

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question