请帮我解决我在这里做的错误
factory.js
angular.module('MyApp').factory('MilkFactory', function ($http) {
var GeneralService = {};
GeneralService.DoCal = function () {
return $http({
url: 'http://localhost:10948/Api/Home/GetEmployee',
method: 'Get',
contentType: 'application/x-www-form-urlencoded'
EmpCtrl.js
angular.module('MyApp')
.controller('EmployeeController', function ($scope, EmployeeService, $q, MilkFactory) {
$scope.GetFactory = function () {
MilkFactory.DoCal().then(function () {
alert('Milk is calling...')
return
})
}
答案 0 :(得分:1)
您需要从工厂返回服务对象
angular.module('MyApp').factory('MilkFactory', function ($http) {
var generalService = {};
generalService.DoCal = function () {
return $http({...});
};
return generalService;
});