Created
November 9, 2015 20:40
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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