[英]Angular JS TypeError: $http is not a function
I have read through all the posts where people get this issue where $http is not a function, and it looks like for the most part it is due to injections being done in the wrong order. 我已经阅读了所有帖子,其中人们得到这个问题,其中$ http不是一个函数,并且看起来大多数情况下它是由于以错误的顺序进行注入。
My module definition looks like this: 我的模块定义如下所示:
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) {
});
};
}
])
Any suggestions would be greatly appreciated. 任何建议将不胜感激。
Remove $http
parameter from makeCall
function, which is killing the existence of $http
dependency injected over controller. 从makeCall
函数中删除$http
参数,这会makeCall
通过控制器注入的$http
依赖性的存在。 Basically when you are adding it on function, it is setted as undefined
基本上,当您在函数上添加它时,它被设置为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) {
}
);
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.