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..!!

1 Answer 1

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);
                            }
                    );
    },
}]);
Sign up to request clarification or add additional context in comments.

5 Comments

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
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
I am getting this error [$injector:unpr] errors.angularjs.org/1.5.0/$injector/…
Am I not supposed to add "homeApp.config(...)" ??
check "$injector.get("$http")" spelling, look like missing the $ prefix

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.