简体   繁体   English

错误:[$ injector:nomod]模块“ myApp.view1”不可用

[英]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.

相关问题 错误:[$ injector:nomod]模块不可用 - Error: [$injector:nomod] Module is not available 错误:[$ injector:modulerr]由于以下原因而无法实例化模块myApp:[$ injector:nomod]模块'ui.bootstrap'不可用 - Error: [$injector:modulerr] Failed to instantiate module myApp due to: [$injector:nomod] Module 'ui.bootstrap' is not available 错误:[$ injector:nomod]模块“ nvd3”不可用 - Error: [$injector:nomod] Module 'nvd3' is not available 由于以下原因无法实例化模块 myApp:错误:[$injector:nomod] - Failed to instantiate module myApp due to: Error: [$injector:nomod] 由于以下原因,无法实例化模块myApp失败:错误:[$ injector:nomod] http://errors.angularjs.org/1.2.26/$injector/nomod?p0=myApp - Failed to instantiate module myApp due to: Error: [$injector:nomod] http://errors.angularjs.org/1.2.26/$injector/nomod?p0=myApp $ injector nomod模块'angularFileUpload'不可用 - $injector nomod Module 'angularFileUpload' is not available AngularJS:未捕获的错误:[$injector:nomod] 模块 _ 不可用! | 对模块的多次引用 - AngularJS: Uncaught Error: [$injector:nomod] Module _ is not available! | Multiple References to Module Angular / Karma:错误:[$ injector:nomod]模块'模块'不可用 - Angular/Karma: Error: [$injector:nomod] Module 'module' is not available 角度错误,在npm build [$ injector:nomod]模块'testApp'不可用 - Angular error, in npm build [$injector:nomod] Module 'testApp' is not available Angular JS错误:[$ injector:nomod]模块'portfolioMockupApp.services'不可用 - Angular JS Error: [$injector:nomod] Module 'portfolioMockupApp.services' is not available
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM