4

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
  • adding JQuery before angular solves this problem. Commented Oct 23, 2015 at 12:22

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.