繁体   English   中英

Angular JS TypeError:$ http不是函数

[英]Angular JS TypeError: $http is not a function

我已经阅读了所有帖子,其中人们得到这个问题,其中$ http不是一个函数,并且看起来大多数情况下它是由于以错误的顺序进行注入。

我的模块定义如下所示:

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参数,这会makeCall通过控制器注入的$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) {

      }
   );
};

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM