2016-10-21 2 views
-1

후 오류가 발생합니다 :AngularJS와 내가 오류가 내 AngularJS와 코드를 축소에 후 작게하다

모듈 응용 프로그램을 인스턴스화하는 데 실패로 인해 : 오류 : [$ 주입기 : unpr] 알 수없는 제공 : t

코드 - 생성 플래그없이 실행하는 경우에만 코드가 작동합니다.

//All dependencies used in below are minified in a single file 

(function(){ 
angular 
    .module('app', [ 
     'ngMessages', 
     'ngStorage', 
     'ngAnimate', 
     'toastr', 
     'ngSanitize' 
     ]); 
})(); 

서비스 코드

(function(){ 
'use strict'; 

angular 
.module('app') 
    .factory('dataservice', dataservice); 

    dataservice.$inject = ['$http','$localStorage','toastr']; 

    function dataservice($http,$localStorage,toastr) { 

      //Code inside this function uses all 3 dependencies injected 
    } 
    })(); 

컨트롤러 코드

(function(){ 

    'use strict'; 

    angular 
    .module('app') 
    .controller('LoginController',LoginController); 

LoginController.$inject = ['$localStorage','dataservice','toastr','$scope','$sanitize']; 

    function LoginController($localStorage,dataservice,toastr,$scope,$sanitize) { 

     /// All 5 dependencies injected here are used inside this function. 
    } 
})(); 
+0

동해안 DDoS의 링크를 기수로 올리는데 어려움을 겪고 있습니다. 그러나 DDoS를 검토해보십시오. Angification을 깨는 문제를 해결합니다. –

답변

0

당신이 당신의 모듈을 등록하기 전에 $inject 속성을 설정하십시오 :

(function(){ 
    'use strict'; 

    dataservice.$inject = ['$http','$localStorage','toastr']; 

    function dataservice($http,$localStorage,toastr) { 

      //Code inside this function uses all 3 dependencies injected 
    } 

    angular 
     .module('app') 
     .factory('dataservice', dataservice); 
})(); 
0123을

또는 심지어 을 없애고 분화하기 전에 빌드 단계로 ng-annotate을 추가 할 수 있습니다.

+0

나는이 코드가 똑같은 오류를 던지더라도 주석을 달아야한다. –

+0

예, 엄격한 모드를 사용하는 것이 항상 바람직합니다. – leitasat

+0

@tryingtolearn 다른 모듈도 바꿨습니까? –