I am trying to load modules progressively. I made a file ‘lazyModule.js’ and I load this module using oclazyLoad. When I define myModule.js dependency in this lazyModule.js, it throws following error on console:
No module found during bootstrap, unable to init ocLazyLoad. You should always use the ng-app directive or angular.boostrap when you use ocLazyLoad.
lazyModule.js
define([
'angular',
'components/infrastructure/myModule'
], function(angular) {
'use strict';
return angular.module('lazyModule',
[
'myModule'
]);
});
myModule.js
define([
'angular',
'ui-bootstrap',
'ocLazyLoad'
], function initModule(angular) {
'use strict';
angular.module('html.myModule', [ 'oc.lazyLoad']);
});
This is how i am lazy loading lazyModule.js:
initializeLazyModule: function(scope) {
var template;
try{
// checking for existing module
angular.module('lazyModule');
isLoaded=true;
}catch(err) {
isLoaded=false;
}
if (!isLoaded) {
return require(['apps/controlCenter/lazyModule'], function() {
$ocLazyLoad.inject('lazyModule');
ControlCenterUtilities.checkAndApplyScope(scope);
$compile($('#my-module'))(scope);
});
}
else {
return;
}
}
Although, when I remove the dependency for oc.lazyLoad module from myModule.js, the console error goes away.
But i do not have option to remove oc.lazyload module dependency from myModule, since it will break for some other component which is consuming my module directly without having loaded oclazyload already.
Its basically happening because oc.lazyload module is being injected twice. Please help