2015-08-28 90 views
4

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

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

如果我在'ui.calendar'模块它的工作原理把moment.js,但我想单独加载它,因为我在我的应用程序中有另一个视图,我只使用了moment.js,并不需要所有的依赖关系。

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

预先感谢您。

回答

1

是的,你可以做到这一点:

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

时要加载的模块陆续在每个单独的国家可以使用amers answer。 地说:

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

如果你想总是加载在意甲的模块,你可以在全局参数serie

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