Book Image

Data Oriented Development with Angularjs

Book Image

Data Oriented Development with Angularjs

Overview of this book

Table of Contents (17 chapters)
Data-oriented Development with AngularJS
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Promise


While working with Angular/JavaScript, or any technology for that matter, there are scenarios when we need to make asynchronous calls—a very common example is of calling a web API. Obviously, when we call a remote API, we can't call it synchronously, because all further processing stops until that call completes. One of the ways of calling a function asynchronously is using a callback. However, callbacks make the code look convoluted. Sometimes, if you have deeply nested callbacks, then life becomes even more difficult. Promises solve these issues and make the intent of the code very clear. The Promise API is part of the ECMAScript 6 (ES6 Harmony) proposal, but there are implementations of it, which we can use even now.

A Promise object (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) is used for deferred and asynchronous computations. A Promise object is in one of the following states:

  • Pending: This is an initial state, not fulfilled or rejected...