Skip to content

Instantly share code, notes, and snippets.

@hcabnettek
Created March 12, 2013 21:12
Show Gist options
  • Save hcabnettek/5147081 to your computer and use it in GitHub Desktop.
Save hcabnettek/5147081 to your computer and use it in GitHub Desktop.
angular.module('SweetMvcApp.services', [])
.factory('tokenService', function ($http, $q) {
function getToken() {
$http.defaults.useXDomain = true;
delete $http.defaults.headers.common['X-Requested-With'];
var deferred = $q.defer(),
ajxArgs = {
type: 'get',
url: 'http://localhost:1187/api/values',
dataType: 'json'
};
$http(ajxArgs)
.success(function (data, status) {
deferred.resolve(data);
}).error(function (data, status) {
deferred.reject(data);
});
return deferred.promise;
}
return {
getToken: getToken
};
});
angular.module('SweetMvcApp', ['SweetMvcApp.services'])
.run(['tokenService',function (tokenService) {
var promise = tokenService.getToken();
promise.then(function (data) {
console.log('success ' + data);
}, function (data) {
console.log('failure ' + data);
});
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment