I'm trying to lazy load a directive in my angular app, using ui.router and oc.lazyLoad. Here is my code :
menu :
<ul>
<li><a ui-sref="home">Home</a></li>
<li><a ui-sref="demo">Demo</a></li>
<li><a ui-sref="test">Test</a></li>
</ul>
<ui-view></ui-view>
route config :
angular.module('app', ['ui.router', 'oc.lazyLoad'])
.config(['$stateProvider', '$urlRouterProvider', function($stateProvider, $urlRouterProvider) {
$stateProvider
.state("demo", {
url:'/demo',
views: {
'lazyLoadView' : {
template: '<demo-directive></demo-directive>'
}
},
resolve : {
loadDemoModule : ['$ocLazyLoad', function($ocLazyLoad) {
console.log('resolving demo lazy load');
return $ocLazyLoad.load('demo.js');
}]
}
})
.state("home", {
templateUrl : 'core/home.html',
url : '/home'
})
}])
and the directive :
angular.module('app').
directive('demoDirective', function() {
return {
restrict: 'E',
scope: {},
template: require('./demo-directive.html'),
// templateUrl: 'demo-directive.html',
controllerAs: 'demo',
controller : ['$timeout', function($timeout) {
console.log('in directive controller');
}]
};
});
I have no errors, the console.log
in resolve function is displayed, the demo.js file is loaded but then noting is happening, console form directive controller is not displayed. I'm trying to follow the first example from ocLazyLoad example
Thanks