ocLazyLoad icon indicating copy to clipboard operation
ocLazyLoad copied to clipboard

moduleLoaded / moduleReloaded events not fired

Open ams10961 opened this issue 8 years ago • 13 comments

Hi, great library, this does exactly what I need, but haven't been able to use the moduleLoaded/moduleReloaded events.

I define a module comprising multiple files, see all files loaded, see individual fileLoaded events, but no moduleLoaded event - is this a known issue?

The bower.json file reports version 1.0.9.

ams10961 avatar Dec 15 '15 16:12 ams10961

+1. Experiencing the same. fileLoaded is not firing as well.

sfdeveloperhub avatar Dec 16 '15 07:12 sfdeveloperhub

Hmm Ok I'll check that :)

ocombe avatar Dec 16 '15 07:12 ocombe

thanks; fileLoaded working fine, only issue is moduleLoaded.

ams10961 avatar Dec 16 '15 08:12 ams10961

@ams10961 fileLoaded events didn't fire for me. However, I turned on debug as true in config. It did spit the fileLoaded events on the console. Can you post an example code of how you got that to work. Here is what I had for the listener : $scope.$on('ocLazyLoad.fileLoaded',function(e,file) {

});

sfdeveloperhub avatar Dec 16 '15 08:12 sfdeveloperhub

Can you try with $rootScope instead of $scope ?

ocombe avatar Dec 16 '15 08:12 ocombe

Didn't work either. Same behavior.

sfdeveloperhub avatar Dec 16 '15 13:12 sfdeveloperhub

@ocombe just tried with the following in my controller, didn't seem to pick up an event; var $rootScope = $injector.get('$rootScope');

// tried moduleLoaded too
$rootScope.$on('ocLazyLoad.moduleReloaded', function(e, module) {
    $log.debug('module reloaded:' + module);
});

ams10961 avatar Dec 16 '15 20:12 ams10961

@sfdeveloperhub this is my app config function

$ocLazyLoadProvider.config({
      events: true,
      modules: [{
            name: 'module1',
            files: ['file1.js','file1.css']       
          }, {
            name: 'module2',
            files: ['file2.js','file2.css']                   
          }]          
});

in the run function

$ocLazyLoad.load('module1');

then in a controller

$scope.$on('ocLazyLoad.fileLoaded', function(e, file) {
    $log ('file loaded:'+file);
});

all working well.

ams10961 avatar Dec 16 '15 20:12 ams10961

hi.. I wondered if you had any thoughts on where to look for this; I need to load 4 files and then act after the final one has loaded; I had a quick check of the source code, saw that ocLazyLoad.core.js:192 seems to broadcast the module loaded event, but can't see it triggered when I load from a module.. thanks..

ams10961 avatar Jan 24 '16 15:01 ams10961

How will you load the module ? If you use the service then it returns a promise and you can chain with then(function() { ... })

ocombe avatar Jan 24 '16 17:01 ocombe

hi.. thanks, I used this approach and worked around it. The odd thing is that I didn't notice the load module event thrown when I enabled debug mode. The broadcast function (ocLazyLoad.core.js:353) looks like it should log an event being thrown.

ams10961 avatar Jan 29 '16 05:01 ams10961

Seems like this issue has been resolved right? I'd love it if we could help @ocombe to keep the issue number down by letting him know when the issue can be closed.

dgreene1 avatar May 09 '17 14:05 dgreene1

I think the issue has only been worked around, not resolved..

ams10961 avatar May 09 '17 15:05 ams10961