This problem has been taking up the last day or so.
I\'ve been trying to get my AngularJS application to load the script files for each state\'s components lazily. I\'m
Here's the code for an Angular module lazy
, depending on the ui.router
module. When it's included in your module's dependencies, the lazy loading functionality of the state's scripts will be enabled. I've included examples of the primary app module, a few lazy components, and my index.html
, sanitized for demonstration purposes. I'm using the Script.js library to actually handle the script loading.
angular-ui-router-lazy.js
/**
* Defines an AngularJS module 'lazy' which depends on and extends the ui-router
* module to lazy-load scripts specified in the 'scripts' attribute of a state
* definition object. This is accomplished by registering a $stateChangeStart
* event listener with the $rootScope, interrupting the associated state change
* to invoke the included $scriptService which returns a promise that restarts the
* previous state transition upon resolution. The promise resolves when the
* extended Script.js script loader finishes loading and inserting a new