gpt4 book ai didi

angularjs - ocLazyLoad 中的模块如何加载、并行或按顺序加载?

转载 作者:行者123 更新时间:2023-12-04 15:20:51 25 4
gpt4 key购买 nike

我正在使用 ocLazyLoad库来实现我项目中所有依赖项的延迟加载。我知道默认情况下文件是并行加载的,为了使其按顺序加载,我应该使用 serie:true https://github.com/ocombe/ocLazyLoad/issues/47

来自 this thread我知道我可以串联加载模块:

Yes the files are loaded in parallel, if you want to multiple modules at the same time and that they require one another you either need to define them in different object params:


$ocLazyLoad.load([{
name: 'TestModule',
files: ['testModule.js', 'testModuleCtrl.js', 'testModuleService.js']
},{
name: 'AnotherModule',
files: ['anotherModule.js']
}]);

现在我尝试在我的应用程序中加载 FullCalendar 所需的所有依赖项,这是我的 ocLazyLoad 配置文件:
$ocLazyLoadProvider.config({
debug: true,
modules: [{
name: 'ngCkeditor',
files: [
'resources/bower_components/ng-ckeditor/libs/ckeditor/ckeditor.js',
'resources/bower_components/ng-ckeditor/ng-ckeditor.min.js',
'resources/bower_components/ng-ckeditor/ng-ckeditor.css'
],
serie: true
},{
name: 'ui.calendar',
files: [
'resources/bower_components/fullcalendar/dist/fullcalendar.min.js',
'resources/bower_components/fullcalendar/dist/lang/he.js',
'resources/bower_components/fullcalendar/dist/gcal.js',
'resources/bower_components/angular-ui-calendar/src/calendar.js',
'resources/bower_components/fullcalendar/dist/fullcalendar.min.css'
],
serie: true
},{
name: 'ngFileUpload',
files: [
'resources/bower_components/ng-file-upload/ng-file-upload.min.js'
]
},{
name: 'momentjs',
files: [
'resources/bower_components/moment/min/moment.min.js'
]
}]
});

这是我的路由器的一部分:
.state('schedule',{
url: '/schedule',
controller: 'ScheduleController',
templateUrl: 'schedule.html',
resolve: {
loginRequired: loginRequired,
loadMyCtrl: ['$ocLazyLoad', function($ocLazyLoad) {
// you can lazy load files for an existing module
return $ocLazyLoad.load(['momentjs','ui.calendar','ngCkeditor']);
}]
}
})

尽管有那个模块 'momentjs'首先定义我仍然得到一个错误: Uncaught ReferenceError: moment is not defined
如果我把 moment.js'ui.calendar'模块它可以工作,但我想单独加载它,因为我的应用程序中有另一个 View ,我只使用 moment.js 并且不需要所有依赖项。

所以,我的问题是,如何使模块(不是文件)加载到系列中,而不是文件,或者如果它们已经加载到系列中,什么会导致我的错误?

先感谢您。

最佳答案

您可以使用 amers answer当您想在每个单独的状态下一个接一个地加载模块时。
放:

$ocLazyLoad.load(['momentjs','ui.calendar','ngCkeditor'], 
{serie: true}).then(function() {
// done..
});

如果你想总是在一个系列中加载模块,你可以设置全局参数 serie :
$ocLazyLoadProvider.config({
serie: true,
modules: [{
...
}]

关于angularjs - ocLazyLoad 中的模块如何加载、并行或按顺序加载?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32274048/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com