2

I'm trying to find a tool or a .js lib to lazy load my scripts on demand of the routes/urls'.

Basically, I want to:

state = {
  state: 'widgets',
  config: {
     url: '/',
     templateUrl: 'modules/widgets/templates/widgets.template.html',
     resolve: {
         // load the .js  somehow
     }          
}
$stateProvider.state(state.state, state.config);

have anyone already done that? or is there a stand for lazy load .js files?

Thanks!

Partha Sarathi Ghosh
  • 10,936
  • 20
  • 59
  • 84
Alvaro Silvino
  • 9,441
  • 12
  • 52
  • 80

2 Answers2

1

Probably not exactly what you need, but yes, you can use $controllerProvider. you can find a very nice article here that explains lazy loading in angular - http://ify.io/lazy-loading-in-angularjs/

check this out - AngularJS: lazy loading controllers and content and the lazy load library https://oclazyload.readme.io/

Community
  • 1
  • 1
Rabi
  • 2,210
  • 17
  • 18
1

You can use UI-Router Extras Future States https://christopherthielen.github.io/ui-router-extras/#/future

There is a yeoman generator: https://github.com/matoilic/generator-angular-lazy which can get you started quickly with ocLazyLoad + Future States

Chris T
  • 8,186
  • 2
  • 29
  • 39