单页的应用程序 - 加载JS文件动态基于局部视图 [英] Single page application - load js file dynamically based on partial view

查看:102
本文介绍了单页的应用程序 - 加载JS文件动态基于局部视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚开始学习角在这里跟随教程 - http://docs.angularjs.org/tutorial/step_00

I've just started learning Angular and following the tutorial here - http://docs.angularjs.org/tutorial/step_00

我下载了从GitHub种子的例子,它的伟大工程。我有一个问题,虽然 - 如果一个局部视图需要被引用的外部JS文件,它需要被添加到开头index.html文件?我想要的应用尽可能精简,只希望包括所需的present视图中的JS引用。是否有可能基于视图动态加载js文件?

I'm downloaded the seed example from GitHub and it works great. I have a question though - if a partial view requires an external js file to be referenced, does it need to be added to the index.html file at the beginning? I want the app to be as lean as possible and only want to include the js references that are required for the present view. Is it possible to load the js files dynamically based on a view?

推荐答案

我觉得这个功能不是内置在AngularJS。

I think this feature is not built-in with AngularJS.

不过你可以看看这个项目,该项目提供了一个基地项目使用AngularJS与RequireJS按需加载所需的js文件。

However you can have a look at this project which offer a base project for using AngularJS with RequireJS to load on demand the required js files.

<一个href=\"https://github.com/tnajdek/angular-requirejs-seed\">https://github.com/tnajdek/angular-requirejs-seed

如果你的应用是巨大的,它可能是有用的,否则就矫枉过正,因为使用AngularJS刚事实上减少了code的写入量。 Personnally,我在一开始加载所有必要的脚本。

If your application is huge, it might be useful, otherwise it can be overkill because just the fact of using AngularJS reduce the amount of code to be written. Personnally, I load all the necessary scripts at the beginning.

也看看这个帖子从布里昂·福特(谁的工作对AngularJS在谷歌)有关使庞大的应用程序:

Also have a look at this post from Briant Ford (who's working on AngularJS at Google) about making huge apps:

<一个href=\"http://briantford.com/blog/huuuuuge-angular-apps.html\">http://briantford.com/blog/huuuuuge-angular-apps.html

这篇关于单页的应用程序 - 加载JS文件动态基于局部视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆