Angular Lazy loading
Preparing your project for lazy loading
After including oclazyload.js in your index file, declare ocLazyLoad as a dependency in app.js
//Make sure you put the correct dependency! it is spelled different than the service!
angular.module('app', [
'oc.lazyLoad',
'ui-router'
])
Usage
In order to lazily load files inject the $ocLazyLoad service into a controller or another service
.controller('someCtrl', function($ocLazyLoad) {
$ocLazyLoad.load('path/to/file.js').then(...);
});
Angular modules will be automatically loaded into angular.
Other variation:
$ocLazyLoad.load([
'bower_components/bootstrap/dist/js/bootstrap.js',
'bower_components/bootstrap/dist/css/bootstrap.css',
'partials/template1.html'
]);