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:
var angularApp = angular.module('myApp',
['oc.lazyLoad', 'pascalprecht.translate', 'chart.js']);
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:
//Load here.
//$ocLazyLoad.load('./panel/dist/test.js');
angular.module('myApp', ['chart.js', [
'./panel/dist/static/chart.min.js',
'./panel/dist/static/angular-chart.min.js'
]]);
$ocLazyLoad.load('./panel/dist/static/chart.min.js');
$ocLazyLoad.load('./panel/dist/static/angular-chart.min.js');
But I got this error:
angular-chart.min.js:10Uncaught Error: Chart.js library needs to included, see http://jtblin.github.io/angular-chart.js/
First, you do not need to inject chart.js in your dependency injection, this should be your module:
Now, you want to have access to some libraries from different controllers (let's say routes), as you said you do not use
$stateProvider
which means you do not useui-router
(which is a third-party library to work with routes and URLs).This is my suggestion (just a simple solution):
By the way, if you are using
ui.router
, this Github issue would be useful for you