Your service should look something like this:
angular.module('testaccount', []). factory('TestAccount', function($http) { var TestAccount = {}; TestAccount.get = function(applicationId, callback) { $http.get('/Admin/GetTestAccounts?applicationId=' + applicationId).success(function(data) { callback(data); }); }; return TestAccount; });
Your controller needs to enter the service, call the service object with the parameter and send the callback function:
angular.module('test', ['testaccount']).controller('TestCtrl', function ($scope, TestAccount) { $scope.selectedTestAccount = null; $scope.testAccounts = []; TestAccount.get(3, function (data) { $scope.testAccounts = data; }) }
Learn more about dependency injection services in a tutorial.
Foo l
source share