javascript - 如何使用 angular.js 包含 .js 文件

标签 javascript angularjs

我需要使用 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 文件中。

当然,当你开发时它们将是不同的文件,所以你应该使用 诸如 GruntGulp 之类的任务运行程序可以为您执行此操作。

我建议您使用 Yeomen generator angular generator

它将使用 Grunt 和其他有趣的东西为您设置一个工作的 Angular 应用程序。

关于javascript - 如何使用 angular.js 包含 .js 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33184527/

相关文章:

javascript - 在 angular/angularjs 混合应用程序中将 downgradeModule 与 downgradeInjectable 结合使用会导致错误

javascript - 正则表达式语法错误 - 无需重复

javascript - 在 AngularJS 中放置 $.draggable() 后,如何从模型中删除?

javascript - Angular Routing ngRoute 无法提取我的其他 HTML 文件

javascript - 函数和闭包可以替代 Javascript 中的类吗?

javascript - jQuery 循环,同时延迟更新 HTML

javascript - Reactjs - 无法将 onClick 应用于渲染的组件

javascript - 尝试导航到另一个页面时 IE7 和 IE8 中出现 "Stop running this script"错误

c# - 如何上传csv文件并解析它?

javascript - 如何使用 ng-repeat 迭代存储在对象中的数组