Skip to content

Added 'how to load module with webpack' guide #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions _guide/010. lazyloading.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,51 @@ This may include:
##


## Load modules with ocLazyLoad and webpack

Create a config function and provide your state config there.

### lazy.js
```
export default angular
.module('lazyLoadedModule', ['ui.router'])
.component('lazy', {
restrict: 'E',
template: '<div>lazy loaded</div>',
})
.name;
```
### lazy.config.js
```
export default function($stateProvider) {
'ngInject';
$stateProvider.state('lazy', {
component: 'lazyLoaded',
resolve: {
loadModule: function($q, $ocLazyLoad) {
'ngInject';
const d = $q.defer();
require.ensure([], function() {
const waiting = require('./lazy');
$ocLazyLoad.load({name: waiting.default});
d.resolve(waiting.default);
});
return d.promise;
},
},
});
}
```

Simply add it to your angular app
### app.js
```
import lazy_load_state from './lazy.config
angular
.module('app', [
'oc.lazyLoad',
'ui.router'
])
.config(lazy_load_state)
.component('app', AppComponent);
```