Last active
February 19, 2016 21:36
-
-
Save brandonroberts/4f793f79c04181633f9a to your computer and use it in GitHub Desktop.
Component Router Lazy Loading
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
var app = angular.module('myApp', ['oc.lazyLoad', 'ngComponentRouter']); | |
app.component('app', { | |
template: [ | |
'<a ng-link="[\'Home\']">Home</a> |', | |
'<a ng-link="[\'About\']">About</a> |', | |
'<a ng-link="[\'User\', \'Profile\']">User Profile</a>', | |
'<hr>', | |
'<ng-outlet></ng-outlet>' | |
].join('\n'), | |
controller: ['$router', '$ocLazyLoad', function($router, $ocLazyLoad) { | |
$router.config([ | |
{ path: '/', name: 'Home', component: 'home' }, | |
{ path: '/about', name: 'About', component: 'about' }, | |
{ | |
path: '/user/...', | |
name: 'User', | |
loader: function() { | |
// lazy load the user module | |
return $ocLazyLoad.load('user.js') | |
.then(function() { | |
// return the user component name | |
return 'user'; | |
}); | |
} | |
} | |
]); | |
}] | |
}); | |
app.component('home', { | |
template: 'Welcome Home' | |
}); | |
app.component('about', { | |
template: 'About Me' | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment