Angularjs 为什么函数不返回承诺';无法读取属性';然后';未定义的';?
出现这个错误“无法读取属性”然后“未定义”我想知道工厂为什么不返回对象 控制器:Angularjs 为什么函数不返回承诺';无法读取属性';然后';未定义的';?,angularjs,Angularjs,出现这个错误“无法读取属性”然后“未定义”我想知道工厂为什么不返回对象 控制器: angular .module('sfcMachinesFieldDefinitions') .controller('MachinesListController', ['$translate', '$http', '$scope', '$state', 'ListOfMachines', function ($translate, $http, $scope, $state, ListOfMa
angular
.module('sfcMachinesFieldDefinitions')
.controller('MachinesListController', ['$translate', '$http', '$scope', '$state', 'ListOfMachines',
function ($translate, $http, $scope, $state, ListOfMachines) {
var vm = this;
vm.allMachines = function () {
return ListOfMachines.allMachines().then(function (response) {
console.log('The respounse' + JSON.stringify(response))
vm.response = response;
})
return response;
};
服务工厂:
angular
.module('sfcMachinesFieldDefinitions')
.factory('ListOfMachines', ['$http', function ($http) {
return {
allMachines: function () {
$http.post('MachineList/GetAllMachines/').then(function (response) {
return response;
})}
};
}]);
它不会返回对象,因为您没有返回它 应该是
...
allMachines: function () {
return $http.post('MachineList/GetAllMachines/')...
}
...