Vish Vish - 4 months ago 30
AngularJS Question

Circular dependency angularjs

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

Answer

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