【问题标题】:AngularJS calling API giving injector errorAngularJS调用API给注入器错误
【发布时间】:2016-01-25 18:32:36
【问题描述】:

当我尝试使用 $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:453https://localhost:44300/Scripts/vendor/angular.min.js:32:18 在 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:495https://localhost:44300/Scripts/vendor/angular-route.min.js:6:446

【问题讨论】:

    标签: angularjs api http


    【解决方案1】:

    你在声明 '$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;
                })
        }
    }
    

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

    【讨论】:

    • @javier_el_bene - 我们都去过那里.. 尝试了解提供程序和可注入的工作方式并了解 angularjs 奇怪的堆栈跟踪(:
    猜你喜欢
    • 1970-01-01
    • 2017-01-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-06
    • 2016-09-16
    • 2014-07-02
    • 2015-11-07
    相关资源
    最近更新 更多