[英]unable to init ocLazyLoad error while including dependency inside a lazyloaded module
I am trying to load modules progressively. 我正在尝试逐步加载模块。 I made a file 'lazyModule.js' and I load this module using oclazyLoad.
我制作了一个文件“ lazyModule.js”,并使用oclazyLoad加载了此模块。 When I define myModule.js dependency in this lazyModule.js, it throws following error on console:
当我在此lazyModule.js中定义myModule.js依赖项时,它将在控制台上引发以下错误:
No module found during bootstrap, unable to init ocLazyLoad.
引导过程中未找到模块,无法启动ocLazyLoad。 You should always use the ng-app directive or angular.boostrap when you use ocLazyLoad.
使用ocLazyLoad时,应始终使用ng-app指令或angular.boostrap。
lazyModule.js lazyModule.js
define([
'angular',
'components/infrastructure/myModule'
], function(angular) {
'use strict';
return angular.module('lazyModule',
[
'myModule'
]);
});
myModule.js 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: 这就是我懒于加载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. 虽然,当我从myModule.js中删除oc.lazyLoad模块的依赖项时,控制台错误消失了。
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. 但是我没有选择从myModule中删除oc.lazyload模块依赖项的选项,因为它会破坏其他一些直接消耗我的模块而又没有加载oclazyload的组件。
Its basically happening because oc.lazyload module is being injected twice. 这基本上是因为oc.lazyload模块被注入了两次。 Please help
请帮忙
I have found solution to this. 我已经找到解决方案。
oc.lazyLoad should not be included in the angular dependency of new angular module creation, if oc.lazyLoad is already loaded through bootstrap angular module. 如果oc.lazyLoad已通过引导角度模块加载,则不应将oc.lazyLoad包括在新角度模块创建的角度相关性中。 oc.lazyLoad tries to initialize itself whenever it is included in the new module dependency.
每当新模块依赖项中包含oc.lazyLoad时,它都会尝试对其进行初始化。
lazyModule.js lazyModule.js
define([
'angular',
'components/infrastructure/myModule'
], function(angular) {
'use strict';
var dependentModules = [
try {
angular.module('oc.lazyLoad');
} catch (moduleError) {
dependentModules.push('oc.lazyLoad');
}
return angular.module('lazyModule', dependentModules);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.