O'Reilly logo

AngularJS Web Application Development Cookbook by Matt Frisbie

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Understanding and implementing a basic promise

Promises are absolutely essential to many of the core aspects of AngularJS. When learning about promises for the first time, the formal terms can be an impediment to their complete understanding as their literal definitions convey very little about how the actual promise components act.

How to do it…

A promise implementation in one of its simplest forms is as follows:

// create deferred object through $q api var deferred = $q.defer(); // deferred objects are created with a promise attached var promise = deferred.promise; // define handlers to execute once promise state becomes definite promise.then(function success(data) { // deferred.resolve() handler // in this implementation, data === 'resolved' }, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required