AngularJS模板。内蒙古JS无法执行 [英] AngularJS template. Inner JS not execute
问题描述
我有很多模板的html页面,其中包括JS code。 JS不执行时,我RouteProvider加载这个模板之一。
我不想使用eval。
我可以在外部.js文件和使用requireJS写我的code,但我不知道我怎么能关闭与requireJS我的未使用js文件。
你能告诉我怎么可以在我装模板页面执行我的JS code?
I have many template html page, which include js code. JS do not execute when my RouteProvider loads one of this template. I do not want to use eval. I can write my code at outer .js files and use requireJS, but I dont know how I can deactivate my "unused" js file with requireJS. Can you tell me how can I execute my JS code at my loaded template page?
推荐答案
在当前版本(1.0.4和1.1.2)AngularJS会的不的执行包含在任何JavaScript code部分通过 templateUrl
规定(或模板
)。
In the current version (1.0.4 and 1.1.2) AngularJS will not execute any JavaScript code contained in a partial specified via templateUrl
(or template
).
目前最好的选择是pre-负荷大部分$ C $的ç前期。人们用requireJS试验,有关于它的很多问题和邮件列表。但事实是 - 当按需加载可以为控制器和谐音来完成 - 一般的按需负载不能很好地支持(见的如何在模块化减轻AngularJS?了解更多关于这个)。在实践中,可能不是因为问题AngularJS书面code往往是真的,真的很简洁,以便pre装东西的前期没有对性能不利(相反,因为所有的code是浏览器有没有连接到延时点播负载)。
At the moment your best option is to pre-load most of the code up-front. People were experimenting with requireJS and there are many questions about it on SO and the mailing list. But the truth is that - while loading on-demand can be done for controllers and partials - in general on-demand load is not well supported (see How is modularity mitigated in AngularJS? for more on this). In practice it might not be a problem since code written with AngularJS tends to be really, really concise so pre-loading things up-front doesn't have adverse performance implications (on the contrary, since all the code is in a browser there are no delays linked to on-demand load).
点播负载是正在处理作为AngularJS 2.0部分的功能。
Load on-demand is a feature that is being worked on as part of AngularJS 2.0.
这篇关于AngularJS模板。内蒙古JS无法执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!