2016-10-21 5 views
-1

後にエラーがスローされます。AngularJsは、私はエラーを取得する私のangularjsコードを縮小化した後、縮小化

モジュールアプリをインスタンス化できませんでしたが原因: エラー:[$インジェクター:UNPR]不明者:トン

コードは、 - 生成フラグを除き、ギャルプを実行した場合にのみ機能します。

//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のリンクを上げるのは苦労していますが、ng-annotateをチェックしてください。これは、Minification breaking Angularの問題を解決します。 –

答えて

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); 
})(); 

また、を取り除くこともできます。これには、換算前に構築ステップとしてng-annotateを追加します。

+0

私はng-annotateを試してください。このコードでも同じエラーがスローされました。 –

+0

ええ、それを強制する厳密なモードを使用する方が常に良いです。 – leitasat

+0

@tryingtolearn他のモジュールも変更しましたか? –

関連する問題