admin管理员组文章数量:1386673
I'm new to AngularJS and am creating an app which will be built using Grunt.
When I build and run my app, I'm noticing some issues related to dependency load order:
Uncaught Error: [$injector:nomod] Module 'mypany.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.
.2.13/$injector/nomod?p0=mypany.admin.forms
In the built app file, the module is being used before it is declared:
angular.module('mypany.admin.forms').controller('editController', ['$scope', function($scope) {
// ...
}]);
angular.module('mypany.admin.forms', [])
.config(['$routeProvider', function($routeProvider) {
// ...
}]);
Here are pertinent snippets from my project's 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'
}
}
...
});
I know I can solve this by putting all source for a given module into one file; however, I'd like to try and keep each thing (each controller, each service, etc.) in its own file.
How can I solve this dependency load order issue?
I'm new to AngularJS and am creating an app which will be built using Grunt.
When I build and run my app, I'm noticing some issues related to dependency load order:
Uncaught Error: [$injector:nomod] Module 'mypany.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/1.2.13/$injector/nomod?p0=mypany.admin.forms
In the built app file, the module is being used before it is declared:
angular.module('mypany.admin.forms').controller('editController', ['$scope', function($scope) {
// ...
}]);
angular.module('mypany.admin.forms', [])
.config(['$routeProvider', function($routeProvider) {
// ...
}]);
Here are pertinent snippets from my project's 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'
}
}
...
});
I know I can solve this by putting all source for a given module into one file; however, I'd like to try and keep each thing (each controller, each service, etc.) in its own file.
How can I solve this dependency load order issue?
Share Improve this question asked Feb 20, 2014 at 17:58 Chad JohnsonChad Johnson 21.9k36 gold badges116 silver badges218 bronze badges2 Answers
Reset to default 5What order is grunt concatenating your files in? It looks like you're just reading a directory, and if the javascript file that module declaration is in is after the file that the controller is in then the concatenated file will be built in the wrong order.
Probably the simplest solution is to explicitly list the file that contains your module declaration (with []) as the first file in your source array.
For solving dependency load issues I remend you using Require.js
It works very well with Angular and also you have a grunt plugin for making the build.
本文标签: javascriptHow to solve dependency issues with built AngularJS appStack Overflow
版权声明:本文标题:javascript - How to solve dependency issues with built AngularJS app? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744493366a2608870.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论