[英]Error: [$injector:nomod] Module 'myApp.view1' is not available
Please help me to organize code correctly. 请帮助我正确组织代码。 I'm trying to change structure of simple angular-seed project in order to learn how to act with it.
我正在尝试更改简单的角度种子项目的结构,以学习如何使用它。 As I see I have troubles with structuring modules & sub-modules
如我所见,我在构建模块和子模块时遇到麻烦
File app.js 档案app.js
angular.module('myApp.view1');
angular.module('myApp.view2');
angular.module('myApp', [
'myApp.view1',
'myApp.view2',
'ngRoute'
]);
var myApp = angular.module('myApp');
myApp.config(['$routeProvider', function($routeProvider) {
$routeProvider
.when('/view1', {
templateUrl: 'views/view1.html',
controller: 'View1Ctrl'
})
.when('/view2', {
templateUrl: 'views/view2.html',
controller: 'View2Ctrl'
})
.otherwise({
redirectTo: '/view1'
});
}]);
Here's view1.js 这是view1.js
'use strict';
var view1 = angular.module('myApp.view1');
view1.controller('View1Ctrl', [function($scope) {
$scope.firstName = "John";
}]);
And view2.js 和view2.js
'use strict';
var view2 = angular.module('myApp.view2');
view2.controller('View2Ctrl', [function($scope) {
$scope.lastName = "Doe";
}]);
The error is because you are accessing the module and not defining them Define them like - 该错误是因为您正在访问模块而不是定义它们。
angular.module('myApp.view1', []);
angular.module('myApp.view2', []);
assuming that the modules have no dependencies. 假设模块没有依赖性。
And do check out my comment on app structure. 并查看我对应用程序结构的评论。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.