Loading…

How to enable lazy loading in Angularjs?

With lazy loading, JS components can be loaded asynchronously on activation on a specific route.

  • Download and install ocLazyLoad.js
  • Add the module in the application
  • Load the file in the required controller
  • Add to the router’s code as

Example

                                        

resolve: {
     loadMyCtrl: ['$ocLazyLoad', function($ocLazyLoad) {return $ocLazyLoad.load('routerState');
}]}

Suggest An Answer

Our Particitants

You can go with bit easier approch by using Angular CLI forRoot() and forChild() concept it

Latest post from Angular 2 Interview Questions

Ask Question