Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Allow appending to module definitions. #3881

Closed
ProLoser opened this issue Sep 4, 2013 · 4 comments
Closed

Allow appending to module definitions. #3881

ProLoser opened this issue Sep 4, 2013 · 4 comments

Comments

@ProLoser
Copy link
Contributor

ProLoser commented Sep 4, 2013

So... right now, you must do this:

  1. angular.module('myModule', ['dependency1', 'dependency2'])
  2. angular.module('myModule')

If you call 1 more than once, you wipe out your original module. If you call 2 first, you get an error (module undefined).

Right now, a problem exists with lazy-loading and asynchronous loading of assets. But what if you could simply supplement a module definition (instead of throwing errors or overriding it).

Lets say I want to load module.js and controller.js and directive.js asynchronously. But if anything other than module loads first, we get errors. If we add a dependency list in the other files, then the preceeding files are blown away.

Why don't we let you load in your crap in whatever order you want (even declaring the dependencies late) and only start throwing errors if these methods are called AFTER angular.bootstrap()?

This may not make lazy-loading perfect, but it would enable us to perform async loading with greater flexibility. Or perhaps async loading is not beneficial enough to bother with this?

@freewind
Copy link

freewind commented Sep 9, 2014

Any updates to this issue?

@ProLoser
Copy link
Contributor Author

ProLoser commented Sep 9, 2014

I no longer feel this is necessary, although it would be nice to see warnings if we redefine a module (but even this may be beneficial during testing)

@ProLoser ProLoser closed this as completed Sep 9, 2014
@freewind
Copy link

freewind commented Sep 9, 2014

What do you mean of "redefine" an module? If we define a module with different dependency the second time after bootstrap, will the directives from new dependency work immediatly?

If it does, my requirement will be satisfied :)

@freewind
Copy link

freewind commented Sep 9, 2014

I just tried but failed, could you help to see where is wrong?

http://jsbin.com/xukafo/1/edit

What I've done in this code:

  1. At first I just defined a controller. The phone directive in another module is not dependent, so the phone number is not shown.
  2. After 3s, I redefined the app module with additional module which contains the phone directive. But it seems not work.

Posted a question to make it clearer: http://stackoverflow.com/questions/25742259/how-to-redefine-a-module-in-angularjs

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants