Configuration

You can configure the service provider $ocLazyLoadProvider in the config function of your application:

angular.module('app', ['oc.lazyLoad']).config(['$ocLazyLoadProvider', function($ocLazyLoadProvider) {
    $ocLazyLoadProvider.config({
        // ...
    });
}]);

The options are:

Option name

Type

Default value

debug

Boolean

false

events

Boolean

false

modules

Array of Objects

undefined

  • debug: $ocLazyLoad returns a promise that will be rejected when there is an error but if you set debug to true, $ocLazyLoad will also log all errors to the console.
$ocLazyLoadProvider.config({
    debug: true
});
  • events: $ocLazyLoad can broadcast an event when you load a module, a component or a file (js/css/template). It is disabled by default, set events to true to activate it. The events are ocLazyLoad.moduleLoaded, ocLazyLoad.moduleReloaded, ocLazyLoad.componentLoaded, ocLazyLoad.fileLoaded.
$ocLazyLoadProvider.config({
    events: true
});
$scope.$on('ocLazyLoad.moduleLoaded', function(e, module) {
    console.log('module loaded', module);
});
  • modules: predefine the configuration of your modules for a later use. You will have to specify the name of the module here so that we can find the reference later.
$ocLazyLoadProvider.config({
    modules: [{
        name: 'TestModule',
        files: ['js/TestModule.js']
    }]
});
$ocLazyLoad.load('TestModule'); // will load the predefined configuration

Did this page help you?