0

can anyone tell me where is the circular dependency in the following code?

var homeApp = angular.module("homeApp",['ngAnimate', 'ui.bootstrap']);

'use strict';

homeApp.factory('AdminDashboardService', ['$http', '$q', function($http, $q){


    return {


        'response': function(response) {
              // do something on success
              console.log("Yes Command comes here");
              return response;
            },

        getAllHolidays: function(monthYearArrayForHolidayList) {
            console.log("For full list of holidays list length: "+monthYearArrayForHolidayList.length);
            var isMonthly="no";
            return $http.get('/tasktrac/holiday/getHoliday/isMonthly/'+isMonthly+'/'+monthYearArrayForHolidayList)
                    .then(
                            function(response){
                                return response.data;
                            }, 
                            function(errResponse){
                                //console.error('Error while fetching holiday');
                                return $q.reject(errResponse);
                            }
                    );
    },
}]);


homeApp.config(['$httpProvider', function($httpProvider) {  
    $httpProvider.interceptors.push('AdminDashboardService');
}]);

I am stuck at this point please do me a favour in resolving this issue. This is the Error I got on the browser Please click here to see error Thank you..!!

Vish
  • 280
  • 2
  • 18

1 Answers1

4

A $http interceptor could not declare $http as a dependency!

Inject $injector:

homeApp.factory('AdminDashboardService', ['$injector', '$q', function($injector, $q){


    return {


        'response': function(response) {
              // do something on success
              console.log("Yes Command comes here");
              return response;
            },

        getAllHolidays: function(monthYearArrayForHolidayList) {
            console.log("For full list of holidays list length: "+monthYearArrayForHolidayList.length);
            var isMonthly="no";
            return $injector.get("$http").get('/tasktrac/holiday/getHoliday/isMonthly/'+isMonthly+'/'+monthYearArrayForHolidayList)
                    .then(
                            function(response){
                                return response.data;
                            }, 
                            function(errResponse){
                                //console.error('Error while fetching holiday');
                                return $q.reject(errResponse);
                            }
                    );
    },
}]);
fantarama
  • 862
  • 6
  • 14
  • Can you elaborate further, I am sorry I am new to angular js, Can you tell me what exactly I need to do, I did not understand the answer, Please suggest me changes in my code – Vish Jul 12 '16 at 13:32
  • posted fixed code, no much to explain: $http injection replaced with $injector. If you are new to angular be sure to understand Dependecy Injection concepts – fantarama Jul 12 '16 at 13:36
  • I am getting this error [$injector:unpr] http://errors.angularjs.org/1.5.0/$injector/unpr?p0=httpProvider%20%3C-%20http – Vish Jul 12 '16 at 13:48
  • Am I not supposed to add "homeApp.config(...)" ?? – Vish Jul 12 '16 at 13:49
  • check "$injector.get("$http")" spelling, look like missing the $ prefix – fantarama Jul 12 '16 at 13:50