Angularjs 如何为不同的控制器创建不同的文件夹?
下面是scotchApp模块的代码,我在app.js页面中创建了不同的网络控制器。我想为控制器和它们的html文件创建不同的文件夹,这样我就可以轻松地通过不同的控制器。我试着这样做,但当我尝试为控制器使用不同的文件夹时,我得到了一个类似这样的错误:错误:[$injector:modulerr]$injector/modulerr?p0=scotchApp&p1=%5B%24injector%3Amodulerr(长链接)Angularjs 如何为不同的控制器创建不同的文件夹?,angularjs,controllers,Angularjs,Controllers,下面是scotchApp模块的代码,我在app.js页面中创建了不同的网络控制器。我想为控制器和它们的html文件创建不同的文件夹,这样我就可以轻松地通过不同的控制器。我试着这样做,但当我尝试为控制器使用不同的文件夹时,我得到了一个类似这样的错误:错误:[$injector:modulerr]$injector/modulerr?p0=scotchApp&p1=%5B%24injector%3Amodulerr(长链接) 您是否在index.html(即主html文件)中添加了所有具有正确路径和
您是否在index.html(即主html文件)中添加了所有具有正确路径和正确顺序的js文件。如果是,请共享index.html文件和文件夹结构,以便更好地了解问题 编辑- cis300.js-- cis400.js-- app.js-- 请用正确的路径更新所有html路径。例如,如果“views/cis300/cis300.htm”,则为cis300.html的路径,但在您的代码中,您将其称为“views/cis300.html”。另外,在css/images文件夹中添加header.png
如果您面临任何其他问题,请告诉我。因此我不需要总是为不同的控制器js文件使用angular.module(scotchApp.cis300Controller)?是的。你不必每次都使用它。你可以用眼睛来定义它,明白了吗。你给我的那些改变是我有问题的原因。谢谢如果您将控制器放入自己的js文件中并放入自己的文件夹中(如
/controllers/controller1.js
),则在运行共享的代码之前,需要先导入这些文件。这意味着您需要在导入共享的路由文件之前使用
标记导入它们。
'use strict'
var scotchApp = angular.module('scotchApp', ['ngRoute']);
scotchApp.config(function ($routeProvider) {
$routeProvider
.when('/', {
templateUrl: 'views/home.html',
controller: 'mainController'
})
.when('/cis300', {
templateUrl: 'views/cis300.html',
controller: 'cis300Controller'
})
.when('/cis400', {
templateUrl: 'views/cis400.html',
controller: 'cis400Controller'
})
.when('/home', {
templateUrl: 'views/home.html',
controller: 'homeController'
})
.when('/login', {
templateUrl: 'views/login.html',
controller: 'loginController'
});
});
scotchApp.controller('mainController', function ($scope) {
$scope.message = 'Welcome to the CIS Course Enrollment Center!';
});
scotchApp.controller('cis300Controller', function ($scope) {
$scope.message = 'This is a the CIS-300 Section.';
});
scotchApp.controller('homeController', function ($scope) {
$scope.message = 'You have successfully logged in!';
});
scotchApp.controller('cis400Controller', function ($scope) {
$scope.message = 'This is the CIS-400 Page';
});
scotchApp.controller('cis300Controller', function($scope){
$scope.message = 'This is a the CIS-300 Section.';
});
scotchApp.controller('cis400Controller', function($scope){
$scope.message = 'This is the CIS-400 Page';
});