我已经阅读了所有人们遇到 $http 不是函数的问题的帖子,看起来大部分是由于注入(inject)顺序错误所致。
我的模块定义如下:
angular.module("app", []).controller("appCtrl", ['$scope','$http',
function ($scope, $http) {
...
$scope.makeCall= function ($http) {
console.log("HERE");
$http({ method: 'GET', url: <url }).
then(function (response) {
console.log(response.data);
return response.data;
}, function (response) {
});
};
}
])
如有任何建议,我们将不胜感激。
最佳答案
从 makeCall
函数中删除 $http
参数,这将消除通过 Controller 注入(inject)的 $http
依赖项的存在。基本上当你在函数上添加它时,它被设置为 undefined
$scope.makeCall= function () { //<-- removed $http dependency from here
console.log("HERE");
$http({ method: 'GET', url: 'url' })
.then(function (response) {
console.log(response.data);
return response.data;
}, function (response) {
}
);
};
关于javascript - Angular JS 类型错误 : $http is not a function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36188176/