最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Angular JS TypeError: $http is not a function - Stack Overflow

programmeradmin5浏览0评论

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.

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.

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.

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.

Share Improve this question edited Mar 25, 2016 at 20:20 Pankaj Parkar 136k23 gold badges240 silver badges303 bronze badges asked Mar 23, 2016 at 20:33 BrendanBrendan 671 gold badge3 silver badges7 bronze badges 1
  • 3 try this $scope.makeCall= function () { ... – Hadi Commented Mar 23, 2016 at 20:35
Add a ment  | 

1 Answer 1

Reset to default 16

Remove $http parameter from makeCall function, which is killing the existence of $http dependency injected over controller. Basically when you are adding it on function, it is setted as 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) {

      }
   );
};
发布评论

评论列表(0)

  1. 暂无评论