O'Reilly logo

Mastering Web Application Development with AngularJS by Pawel Kozlowski, Peter Bacon Darwin

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

The promise API with $http

Now that we've covered promises we can demystify the response object being returned from the $http method calls. If you recall a simple example from the beginning of this chapter you will remember that $http calls return an object on which the success and error callbacks can be registered. In reality the returned object is a fully fledged promise with two additional, convenience methods: success and error. As any promise, the one returned from a $http call has also the then method which allows us to rewrite the callback registration code in the following form:

var responsePromise = $http.get('data.json');
responsePromise.then(function (response) { $scope.data = response.data; },function (response) { throw new Error('Something ...

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