AngularJS calling API giving injector error

I'm having an injection error when i try to use $http to get a value from an API on my app. I'm including both the code of the module definition and the function which calls the Web API and the error in the browser console.

angular.module('mod-1').controller('Controller', ['$scope','http', 'APICM', '$q', '$filter', '$timeout', 'AppSettings'$modal', 'Dialog', 'title',
function ($scope, $http, API, $q, $filter, $timeout, AppSettings, $modal, Dialog, title) {

    $('.page-title').text(title);

    function getActiveStore() {
      $http.get("https://localhost:44300/api/store/active").success(
            function (response) {
                $scope.currentStore = response;
            })
    }
}

Error: Error: [$injector:unpr] http://errors.angularjs.org/undefined/$injector/unpr?p0=httpProvider%20%3C-%20http at Error (native) at https://localhost:44300/Scripts/vendor/angular.min.js:6:453 at https://localhost:44300/Scripts/vendor/angular.min.js:32:18 at Object.c [as get] (https://localhost:44300/Scripts/vendor/angular.min.js:29:147) at https://localhost:44300/Scripts/vendor/angular.min.js:32:86 at c (https://localhost:44300/Scripts/vendor/angular.min.js:29:147) at d (https://localhost:44300/Scripts/vendor/angular.min.js:29:324) at Object.instantiate (https://localhost:44300/Scripts/vendor/angular.min.js:30:482) at https://localhost:44300/Scripts/vendor/angular.min.js:59:495 at https://localhost:44300/Scripts/vendor/angular-route.min.js:6:446


You forgot $ when declaring '$http':

angular.module('mod-1').controller('Controller', ['$scope','$http', 'APICM', '$q', '$filter', '$timeout', 'AppSettings', '$modal', 'Dialog', 'title',
function ($scope, $http, API, $q, $filter, $timeout, AppSettings, $modal, Dialog, title) {

    $('.page-title').text(title);

    function getActiveStore() {
      $http.get("https://localhost:44300/api/store/active").success(
            function (response) {
                $scope.currentStore = response;
            })
    }
}

This should fix the error you are getting.

链接地址: http://www.djcxy.com/p/13604.html

上一篇: 角度获取请求415错误

下一篇: AngularJS调用API导致注入错误