I have code in my controller that directly called $ http to receive data. Now I would like to move this to a service. Here is what I still have:
My service:
angular.module('adminApp', []) .factory('TestAccount', function ($http) { var TestAccount = {}; TestAccount.get = function (applicationId, callback) { $http({ method: 'GET', url: '/api/TestAccounts/GetSelect', params: { applicationId: applicationId } }).success(function (result) { callback(result); }); }; return TestAccount; });
Inside the controller:
TestAccount.get(3, function (data) { $scope.testAccounts = data; })
How can I change this, instead of passing the result of success back, it returns a promise that I can check to make sure that it succeeded or failed?
user1464139
source share