加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

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

发布时间:2020-12-17 10:22:55 所属栏目:安全 来源:网络整理
导读:我正在使用 ocLazyLoad库来实现项目中所有依赖项的延迟加载.我知道默认文件是并行加载的并且按顺序加载我应该使用serie:true https://github.com/ocombe/ocLazyLoad/issues/47 从this thread我明白我可以加载模块系列: Yes the files are loaded in parall
我正在使用 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'
                        ],{
                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’但我仍然会收到错误:未捕获的ReferenceError:未定义时刻

如果我将moment.js放在’ui.calendar’模块中它可以工作,但是我想单独加载它,因为我在我的应用程序中有另一个视图,我只使用moment.js并且不需要所有依赖项.

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

先感谢您.

如果要在每个单独的状态下一个接一个地加载模块,则可以使用amers answer.
放:
$ocLazyLoad.load(['momentjs','ngCkeditor'],{serie: true}).then(function() {
     // done..
});

如果您希望始终在系列中加载模块,可以设置全局参数系列:

$ocLazyLoadProvider.config({
    serie: true,modules: [{
        ...
    }]

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读