[Angular 2] Using Promise to Http

Source: Internet
Author: User

You can also with Promise for http:

For the service, you need-call Topromise () method:

  Getvehicles (value?: String) {    returnthis. _http.get (' Api/vehicles.json ')      = = <Vehicle[]>Response.json (). Data)      .  Topromise()      . Catch (this. handleError);  }

Then on your controller, you can get the Promise back:

  Getheroes (value?: String) {    this. _vehicleservice.getvehicles (value);  }

But notice this, we assign the Promise to the this.vehices. So it means we use ' async ' pipe:

< ul >  <  *ngfor= "#vehicle of Vehicles | async"    (click)= "SELECT (Vehicle)" >     {{vehicle.name}}  </li></ul  >

[Angular 2] Using Promise to Http

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.