The ability to reply to discussions is limited to PRO members. Want to join in the discussion? Click here to subscribe now.

Chained Promises in Angular

Chained Promises in Angular

7:07
Promises are a fantastic tool in AngularJS. Many times, as you start to chain them together, they become ugly and unwieldy. In this lesson, Thomas will show you an approach for breaking your chained promises down into a flat, clean, readable structure.
Watch this lesson now
Avatar
egghead.io

Promises are a fantastic tool in AngularJS. Many times, as you start to chain them together, they become ugly and unwieldy. In this lesson, Thomas will show you an approach for breaking your chained promises down into a flat, clean, readable structure.

Avatar
Jasper Moelker

Thank you for explaining the key concept of chaining promises with a real-life example!
I do want to remark that both travelService.getFlight & weatherService.getForecast use the departure data that is already available when travelService.getDeparture is resolved. Therefore I think getForecast should not be chained to getFlight but rather directly to getDeparture, just like getFlight. I know this doesn't matter much when everything is resolved in local services, but if this would be remote requests it would delay the process longer than needed, which defeats JavaScript's asynchronous power.

In reply to egghead.io
Avatar
liranviper

I agree.

Also, it doesn't seem right that getDeparture gets its needed data (flight id) as argument, but getForecast gets its needed data (flight date) from scope. its inconsistent and confusing.

it makes more sense that getFlight would instead return the needed data for both (flight object), and both of the other functions would get this flight object as argument.

In reply to Jasper Moelker
HEY, QUICK QUESTION!
Joel's Head
Why are we asking?