我是AngularJS的新手,正在創建一個使用Grunt構建的應用程序。如何解決內置AngularJS應用程序的依賴問題?
當我構建和運行我的應用程序,我注意到有關依賴的加載順序的一些問題:
Uncaught Error: [$injector:nomod] Module 'mycompany.admin.forms' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
http://errors.angularjs.org/1.2.13/$injector/nomod?p0=mycompany.admin.forms
在內置的應用程序文件,宣告前它正在使用的模塊:
angular.module('mycompany.admin.forms').controller('editController', ['$scope', function($scope) {
// ...
}]);
angular.module('mycompany.admin.forms', [])
.config(['$routeProvider', function($routeProvider) {
// ...
}]);
下面是我的項目的gruntfile.js有關片段:
grunt.initConfig({
distdir: 'build',
pkg: grunt.file.readJSON('package.json'),
src: {
js: ['src/**/*.js'],
},
concat: {
dist: {
src: ['<%= src.js %>', '<%= src.jsTpl %>'],
dest: '<%= distdir %>/admin/app.js'
}
}
...
});
我知道我可以解決通過將給定模塊的所有源代碼放入一個文件中;但是,我想嘗試將每個事物(每個控制器,每個服務等)保存在自己的文件中。
如何解決此依賴性加載順序問題?
這就是我的想法。我剛剛嘗試過,而且很有效。 –
我現在正在做的不是列出我的Gruntfile中的單個文件,而是使用一個模式(我的模塊定義在* .module.js文件中),所以他們的名字首先被渲染爲''{.tmp,<%= config .client%>}/{app,components}/**/*。module.js','{.tmp,<%= config.client%>}/{app,components}/**/*。js' '。這可能不適用於更復雜的模塊嵌套結構。 – yorch