AngularJS template. Inner JS not execute

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?


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 ).

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).

Load on-demand is a feature that is being worked on as part of AngularJS 2.0.

链接地址: http://www.djcxy.com/p/90360.html

上一篇: 如何使用EasyMock模拟从抽象类继承的方法?

下一篇: AngularJS模板。 内部JS不执行