ocombe / ocLazyLoad

Lazy load modules & components in AngularJS
https://oclazyload.readme.io
MIT License
2.63k stars 510 forks source link

Directive doesn't work with module names #342

Open jasonconway-williams opened 8 years ago

jasonconway-williams commented 8 years ago

I am using webpack in my project implementing the code splitting feature. I have configured it to load a module named 'panel' on demand via the require.ensure logic.

I also have a directive in my app belonging to the module that I load on demand. I have attached the oc-lazy-load directive to the parent div of the loaded module directive where I specify the name of the 'panel' module:

<div oc-lazy-load="panel">
    <side-panel></side-panel>
</div>

When I run my application even before clicking to load the panel module on demand I receive two errors stating:

File type could not be determined. panel(anonymous function) Error: no file to load has been found, if you're trying to load an existing module you should use the 'inject' method instead of 'load'.

I have read the documentation and looked at the oc-lazy-load source. It states that you can either provide a file path, multiple file paths, objects or the name of the module that I want to load. The directive doesn't seem to work in this way.

jasonconway-williams commented 8 years ago

Just changed the complex application in the examples directory to follow the same logic and it is also throwing the same error. I did the following:

It seems that the call to angular.isDefined returns true regardless of whether the module is actually loaded. I made some changes to see if I could get it working, I did the following:

This worked :+1: I created an extra service to see if DI worked, the service simply populated the controller test variable. I also found (at first) that the grid content generated by the ui-grid directive was not being displayed and found that this was down to the gridModule components being loaded before the ui-grid js and css files. I replaced the file path references in the module declaration with the angular module names and placed the script paths in the index.html file. This worked, Maybe there is something that can be done with regards to dependencies and the order in which they are loaded.

I will try and fork the repo and implement a clean version of my fix. Can you specify how you would like this done? I might be getting the wrong end of the stick but is the broadcasting of events enabled all the time or is it only when it is specified in the config block? I thought that this was only to do with the log output for events? Is it OK to base the logic for the directive on the events being fired?