Skip to content

Instantly share code, notes, and snippets.

@mizrael
Created November 9, 2015 20:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mizrael/b5cb8a35ce4d27004183 to your computer and use it in GitHub Desktop.
Save mizrael/b5cb8a35ce4d27004183 to your computer and use it in GitHub Desktop.
an AngularJs controller that uses a promise to subscribe to call a remote service and handle the results
var myApp = angular.module('myApp',[]);
myApp.controller('FooController', ['$scope', 'fooService', function($scope, fooService) {
var instance = this;
$scope.loadingStatus = 'none';
instance.onBarCompleted = function(){
$scope.loadingStatus = 'completed';
};
instance.onBarError = function(){
$scope.loadingStatus = 'error';
};
$scope.callBar = function() {
$scope.loadingStatus = 'loading...';
fooService.bar()
.then(instance.onBarCompleted)
.catch(instance.onBarError);
}
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment