我需要使用 angular.js 动态包含 javascript 文件。假设我有下面的项目 html View 结构。
1-index.html.
a)hod.html-hodcontroller.js
i)home.html.-homecontroller.js
ii)about.html.-aboutcontroller.js
b)Princpal.html-princpalcontroller.js
i)home.html-homecontroller.js
ii)about.html -aboutcontroller.js
让我解释一下上面的结构。我有一个母版页(i.e-index.html
)。 hod.html 和 Princpal.html
是index.html页面的部分 View 。每个 home.html 和 about.html
都是 hod.html 和 Princpal.html
的部分 View ,所以最后这些是嵌套 View 。这里我将所有 js 文件包含在index.html
页面中的时间但是在这里,当任何部分 View 将附加在索引页面中时,我需要的只是相关的 .js 文件将附加在索引页面中,而不是所有页面中。所以请帮助我做使用 angular.js。
最佳答案
您尝试做的并不是创建 Angular 应用程序的最佳方法。 通常您希望所有代码都在一个 js 文件中。
当然,当你开发时它们将是不同的文件,所以你应该使用 诸如 Grunt 或 Gulp 之类的任务运行程序可以为您执行此操作。
我建议您使用 Yeomen generator 与 angular generator
它将使用 Grunt 和其他有趣的东西为您设置一个工作的 Angular 应用程序。
关于javascript - 如何使用 angular.js 包含 .js 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33184527/