AngularJS template. Inner JS not execute

白昼怎懂夜的黑 提交于 2019-12-10 16:32:52

问题


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:


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.



来源:https://stackoverflow.com/questions/14676695/angularjs-template-inner-js-not-execute

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!