var app = angular.module('app',['ui.router']);
app.service('api',function($http){
var user,autherror, apihost, requestpath;
return {
authorize:function(){
var deferred = $q.defer();
deferred.promise = $http.get(apihost+'/'+requestpath) //$http returns a promise object
.success(function(data){
user = data;
})
.error(function(data){
autherror = data;
});
return deferred.promise; //chains the defer into the $http promise and is returned to the calling context
}
}
app.config(function($urlRouterProvider, $stateProvider){
$urlRouterProvider.when('/login/',login($match, apiServiceService));
$urlRouterProvider.otherwise('/');
});
var function handler(match, api){
api.authorize(match).then(function(){
});
}
Last active
August 29, 2015 13:56
-
-
Save LongLiveCHIEF/8892866 to your computer and use it in GitHub Desktop.
A walkthrough of AngularJS service/factory/provider injenction into a module.config object using deferred promise
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment