2016-07-12 6 views
0

誰でも次のコードの循環依存関係はどこですか?円の依存関係angularjs

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

この時点で私はこの問題を解決してください。 これはブラウザに表示されたエラーです Please click here to see error ありがとうございます!!

答えて

4

$ httpインターセプタは$ httpを依存関係として宣言できませんでした。

を注入$インジェクター:

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

あなたはさらに手の込んだことができ、私は角度のJSに新しいです申し訳ありません、あなたは私がする必要が正確に何を教えてもらえます、私は答えを理解していなかった、私を提案してください。私のコードの変更 – Vish

+0

は固定コードを掲示しました、説明するものはあまりありません:$ http注入は$ injectorに置き換えられました。あなたが角度に慣れていない場合は、Dependecy Injectionのコンセプトを理解してください。 – fantarama

+0

このエラー[$ injector:unpr] http://errors.angularjs.org/1.5.0/$injector/unpr?p0=httpProvider%20% 3C-%20http – Vish