在Angular中,您需要註釋注入器的函數以知道要在函數中注入哪些依賴關係。基本上有三種方法在您的函數中注入依賴關係,正在官方角色網站上描述。這三種方法是:
1.使用內嵌陣列註釋
yourModule.controller('yourController', ['$scope', function($scope) {}]);
2.使用$從功能注入性註釋
var yourController = function($scope) {};
yourController.$inject = ['$scope'];
yourModule.controller('yourController', yourController);
3.Implictly參數名稱
yourModule.controller('yourController', function($scope) {});
現在,當您縮小項目時,您的依賴項名稱將被重命名。 在第一種情況下你的代碼會像
yourModule.controller('yourController', ['$scope', function(e) {}]);
在第三種情況下你的代碼會像
yourModule.controller('yourController', function(e) {});
它會破壞你的應用程序,因爲角沒有辦法認出你的依賴的名字。所以建議不要在你的項目中使用隱式依賴注入。從上面的兩個內聯數組註釋是程序員中最流行的方式。
這些都應該做工精細。看看我的構建腳本:http://github.com/joshdmiller/ng-boilerplate。但我不確定你在這裏具體問的是什麼。你遇到什麼問題? –
app.config(['$ routeProvider',function($ routeProvider){$ routeProvider.something()...}]);在縮小時變成app.config(['$ routeProvider',function(e){ef = function()...),並導致e-> eProvider錯誤。 $ injector or $ inject在應用程序的某處? – user2167582
您提供的代碼對我來說工作得很好 - 再次檢查一下這個鏈接。你能發佈函數的主體嗎? –