AngularJS template. Internal JS is not running

I have many html page templates that include js code. JS is not running when my RouteProvider loads one of these patterns. I do not want to use eval. I can write my code in external .js files and use requireJS, but I don’t know how I can deactivate my "unused" js file with requireJS. Can you tell me how I can execute my JS code on my loaded template page?

+4
javascript angularjs requirejs
source share
1 answer

In the current version (1.0.4 and 1.1.2), AngularJS will not execute any JavaScript code contained in partial, specified via templateUrl (or template ).

At the moment, your best bet is to pre-load most of the code up. People have been experimenting with requireJS, and there are many questions about this on SO and on the mailing list. But the truth is that - on-demand loading can be done for controllers and particulars - in general, on-demand loading is poorly supported (see How does modularity soften in AngularJS? For more information on this). In practice, this may not be a problem, since code written using AngularJS tends to be really, very concise, so preloading things ahead has no adverse performance consequences (on the contrary, since all the code is in the browser, there are no delays associated with load on request).

On-demand loading is a function that is processed as part of AngularJS 2.0.

+2
source share

All Articles