javascript - 将 View 添加到 Angular 种子项目

标签 javascript html angularjs web-applications angular-seed

如何向 Angular-seed 项目添加更多 View ?

我刚开始这个项目,想添加更多 View ,所以我复制了 view2 文件夹并将其重命名为 view3(对文件夹中包含 view2 变量的所有文件执行相同的操作),然后将其添加到模块中。

angular.module('myApp', [
    'ngRoute',
    'myApp.view1',
    'myApp.view2',
    'myApp.view3',
    'myApp.version'
]).
config(['$routeProvider', function($routeProvider) {
  $routeProvider.otherwise({redirectTo: '/view1'});
}]);

view3.js 文件如下所示:

'use strict';

angular.module('myApp.view3', ['ngRoute'])

.config(['$routeProvider', function($routeProvider) {
  $routeProvider.when('/view3', {
  templateUrl: 'view3/view3.html',
  controller: 'View3Ctrl'
 });
}])

.controller('View3Ctrl', [function() {

}]);

您还需要做其他任何与 angular-seed 相关的事情吗,因为我在重新加载页面时遇到了这些错误,而且我真的不知道从哪里开始。一直在查看 Bower_components 文件夹,但其中似乎没有您应该更改的任何内容。

第三行讲的是加载,但是加载到哪里呢?

Uncaught Error: [$injector:modulerr] Failed to instantiate module myApp due to:
Error: [$injector:modulerr] Failed to instantiate module myApp.view3 due to:
Error: [$injector:nomod] Module 'myApp.view3' 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.23/$injector/nomod?p0=myApp.view3
at http://localhost:8000/app/bower_components/angular/angular.js:78:12
at http://localhost:8000/app/bower_components/angular/angular.js:1677:17
at ensure (http://localhost:8000/app/bower_components/angular/angular.js:1601:38)
at module (http://localhost:8000/app/bower_components/angular/angular.js:1675:14)
at http://localhost:8000/app/bower_components/angular/angular.js:3878:22
at forEach (http://localhost:8000/app/bower_components/angular/angular.js:325:18)
at loadModules (http://localhost:8000/app/bower_components/angular/angular.js:3872:5)
at http://localhost:8000/app/bower_components/angular/angular.js:3879:40
at forEach (http://localhost:8000/app/bower_components/angular/angular.js:325:18)
at loadModules (http://localhost:8000/app/bower_components/angular/angular.js:3872:5)
http://errors.angularjs.org/1.2.23/$injector/modulerr?p0=myApp.view3&p1=Err…ocalhost%3A8000%2Fapp%2Fbower_components%2Fangular%2Fangular.js%3A3872%3A5)
at http://localhost:8000/app/bower_components/angular/angular.js:78:12
at http://localhost:8000/app/bower_components/angular/angular.js:3906:15
at forEach (http://localhost:8000/app/bower_components/angular/angular.js:325:18)
at loadModules (http://localhost:8000/app/bower_components/angular/angular.js:3872:5)
at http://localhost:8000/app/bower_components/angular/angular.js:3879:40
at forEach (http://localhost:8000/app/bower_components/angular/angular.js:325:18)
at loadModules (http://localhost:8000/app/bower_components/angular/angular.js:3872:5)
at createInjector (http://localhost:8000/app/bower_components/angular/angular.js:3812:11)
at doBootstrap (http://localhost:8000/app/bower_components/angular/angular.js:1444:20)
at bootstrap (http://localhost:8000/app/bower_components/angular/angular.js:1459:12)
http://errors.angularjs.org/1.2.23/$injector/modulerr?p0=myApp&p1=Error%3A%…calhost%3A8000%2Fapp%2Fbower_components%2Fangular%2Fangular.js%3A1459%3A12) 

最佳答案

您还需要在 index.html 中加载 view3.js 脚本。

关于javascript - 将 View 添加到 Angular 种子项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25687053/

相关文章:

javascript - 鼠标悬停时向图像添加文本

javascript - 如何修复 Angular JS 过滤器?

javascript - AngularJS 与 Vaadin 集成

javascript - 使用回调打印json数据

javascript - 如何从对象数组中获取键和每个键的计数

php - 什么情况下我们不应该在 javascript 中使用 php?

css - 如何使用CSS创建两栏页面布局?

html - WhatsApp Web 喜欢 Content Editable Div

javascript - 使用 jQuery 将 div 动画移出窗口/ View ,调整大小时忽略 css 规则

css - 如何将 Accordion css 更改为纯白色?