Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
angularjs如何设置<;脚本src=";控制员&燃气轮机;取决于index.html中的路由_Angularjs_Dynamic_Controllers - Fatal编程技术网

angularjs如何设置<;脚本src=";控制员&燃气轮机;取决于index.html中的路由

angularjs如何设置<;脚本src=";控制员&燃气轮机;取决于index.html中的路由,angularjs,dynamic,controllers,Angularjs,Dynamic,Controllers,我一直在开发angular.js应用程序,它正在与许多控制器一起发展, 所有文件都包含在index.html文件中,即使当前视图不使用其中一个文件,这也适用于提供程序和其他模块 如何在index.html中根据路由仅调用所需的控制器 我有一个index.html文件,其中包含许多脚本标记: <script src="controller1.js"></script> <script src="controller2.js"></script> &l

我一直在开发angular.js应用程序,它正在与许多控制器一起发展, 所有文件都包含在index.html文件中,即使当前视图不使用其中一个文件,这也适用于提供程序和其他模块

如何在index.html中根据路由仅调用所需的控制器

我有一个index.html文件,其中包含许多脚本标记:

<script src="controller1.js"></script>
<script src="controller2.js"></script>
<script src="controller3.js"></script>

更新: 对问题+答案的更好解释。

您应该让angular根据路由或url为您处理。您最好的选择是查看routeProvider,文档是

用法如下所示:

$routeProvider.when('/Book/:bookId/ch/:chapterId', {
    templateUrl: 'chapter.html',
    controller: ChapterCntl
});

另一个选择是使用Ui路由器,它是routeprovider的扩展。下面是您正在寻找的。

异步模块和一个可以从服务器中提取它们的加载程序。是第一个想到的。你可以找到一个种子项目,其中有如何将RequireJS和AngularJS结合在一起的例子。

你说的“呼叫”是什么意思?要加载一个特定的
js
文件吗?是的,不需要写所有的脚本标记。如果我需要的是RequireJS,我将尝试并发布结果。