Skip to content

Instantly share code, notes, and snippets.

@creimers
Created December 9, 2016 13:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save creimers/73650deea2d3b4801cd3a25481d54783 to your computer and use it in GitHub Desktop.
Save creimers/73650deea2d3b4801cd3a25481d54783 to your computer and use it in GitHub Desktop.
Lazy loading with angular1 component router and webpack code split
class lazyAppCtrl {
constructor($q, $rootRouter, $ocLazyLoad) {
this.$q = $q
this.$rootRouter = $rootRouter
this.$ocLazyLoad = $ocLazyLoad
this.$rootRouter.config([
{
path: '/lazy',
name: 'Lazy',
loader: () => {
let deferred = this.$q.defer();
require.ensure([], () => {
const module = require('./path/to/your/lazy/view/component')
return this.$ocLazyLoad.inject({name: module.default})
.then(() => deferred.resolve('nameOfYourLazyViewComponent') )
});
return deferred.promise
}
}
])
}
}
cont lazyApp {
controller: 'lazyAppCtrl',
template: '...'
}
angular.module('App', [require('oclazyload')])
.component('lazyApp', lazyApp)
.controller('lazyAppCtr', lazyAppCtrl)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment