December 2014
Intermediate to advanced
346 pages
6h 14m
English
Restangular, the extremely popular REST API extension to AngularJS, takes a much more promise-centric approach compared to $resource.
The Restangular REST API mapping will always return a promise. This is shown here:
(app.js) angular.module('myApp', ['restangular']) .controller('Ctrl', function($scope, Restangular) { Restangular .one('widget', 4) // get() will return a promise for the GET request .get() .then( function(data) { // consume response data in success handler $scope.status = 'One widget success!'; }, function(response) { // consume response message in error handler $scope.status = 'One widget failure!'; } ); // generally, the API mapping is stored in a variable, // and the promise-returning ...Read now
Unlock full access