AngularJS调用API给出了喷射器错误

时间:2015-10-26 15:27:10

标签: angularjs api http

当我尝试使用$ http从我的应用上的API获取值时,我遇到了注入错误。我包括模块定义的代码和调用Web API的函数以及浏览器控制台中的错误。

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;
            })
    }
}

错误:     错误:[$ injector:unpr] http://errors.angularjs.org/undefined/ $ injector / unpr?p0 = httpProvider%20%3C-%20http     在错误(本机)     在https://localhost:44300/Scripts/vendor/angular.min.js:6:453     在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)     在https://localhost:44300/Scripts/vendor/angular.min.js:32:86     在c(https://localhost:44300/Scripts/vendor/angular.min.js:29:147)     在d(https://localhost:44300/Scripts/vendor/angular.min.js:29:324)     在Object.instantiate(https://localhost:44300/Scripts/vendor/angular.min.js:30:482)     在https://localhost:44300/Scripts/vendor/angular.min.js:59:495     在https://localhost:44300/Scripts/vendor/angular-route.min.js:6:446

1 个答案:

答案 0 :(得分:2)

你在宣布'$ 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;
            })
    }
}

这应该可以解决您遇到的错误。