Closed m98 closed 7 years ago
Hi! In your module definition you don't have to inject "chart.js"
angular.module('myApp', [ 'ui.router', 'oc.lazyLoad' ]);
If you are using ui.router:
angular.module('myApp').config(
['$stateProvider', '$urlRouterProvider',
function ($stateProvider, $urlRouterProvider) {
$urlRouterProvider.otherwise('/access/signin');
$stateProvider
.state('chart', {
url: '/chart-view',
templateUrl: 'path/to/your/view',
resolve: {
store: function ($ocLazyLoad) {
return $ocLazyLoad.load(
{
serie: true,
name: "chart.js",
files: [
"path/to/Chart.min.js",
"path/to/anguar-chart.min.js",
]
}
);
}
}
});
}
]
);
Thanks 👍
very useful, I also added an answer on Stackoverflow for users who are not using ui-router
(of course not very different)
cool! so you can close the issue!
It actually works .... Hey can you explain me how it is injecting dependency ... TIA ...
This question asked on Stackoverflow but no one answered that, I was curious to know the answer, and I posted that here:
I'm using ocLazyLoad and I have some external angular libraries (Like Chart.js and pascalprecht.translate) and I need to lazy load them in some routes, as you know, for the common angular module dependency injection should be like:
Now, I just need to lazy loading pascalprecht.translate in one of my controllers and also lazy loading chart.js, in another controller, but I still need to add inject them to myApp module but I don't know how to inject and I do not use $stateProvider
I tried this my controller that I needed chart.js:
But I got this error: