Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 为什么函数不返回承诺';无法读取属性';然后';未定义的';?_Angularjs - Fatal编程技术网

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/')...
}
...