Created
September 24, 2014 19:10
-
-
Save chrissearle/cb584ba9281e13ced8c0 to your computer and use it in GitHub Desktop.
AngularJS - service to call http async and return data to controller - is there a better way than exposing the promise itself back to the controller?
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
.factory('someService', ['$http', function ($http) { | |
return { | |
async: function () { | |
return $http.get('someUrl').then(function (response) { | |
return response.data; | |
}); | |
} | |
}; | |
}]).controller('someController', ['$scope', 'someService', function ($scope, someService) { | |
someService.async().then(function (d) { | |
$scope.someData = d; | |
}); | |
}]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment