0

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

0

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

@javier_el_bene - We all been there .. Try to understand how providers and injectables work and understand angularjs weird stacktrace (:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.