marcoslin / angularAMD

Facilitate use of RequireJS in AngularJS
http://marcoslin.github.io/angularAMD
MIT License
734 stars 171 forks source link

How to setup an app.config(...)? #123

Open mpiasta-ca opened 9 years ago

mpiasta-ca commented 9 years ago

Is it possible to setup an app.config(...) in a separate file? I have been building all my app.run() and app.config(...) code in app.js, but that file is becoming too long and unmanageable. When I tried to move a piece of app.confg(...) into a separate file, which I then rename to angularAMD.config(...), browser throws error:

Uncaught Error: angularAMD not initialized. Need to call angularAMD.bootstrap(app) first.

marcoslin commented 9 years ago

Yes, it should be possible but you must do that after angularAMD.boostrap has been called. Unfortunately, .bootstrap is an async call so if you do this on initialisation, you will sometimes get the not initialized error.

I haven't tried this but I would assume if you wrap your angularAMD.config(...) inside a angular.element(document).ready(...), you should ok.

By the way, in case you don't know, app.run equivalent is angularAMD.inject.

mpiasta-ca commented 9 years ago

angular.element(document).ready(...) didn't work, says Need to call angularAMD.bootstrap(app) first. But this works:

define(['angularAMD'], function (angularAMD) {
  require(['app'], function () {
    angularAMD.inject(function (...) {
      //code to execute instead of using app.run(...)
    });
  });
});
marcoslin commented 9 years ago

I see. I think the real answer here is the need to have a bootstrap callback from angularAMD. I need to think about this a bit, as it should address the unit test problems as well.

mpiasta-ca commented 9 years ago

Hey. I'm trying to refactor my app.js file today, so I'm back here again. I think we need to be able to do angularAMD.config(...) and angularAMD.run(...). Is there any reason that wouldn't work?

Note however that in my run(...) statement I am referencing services that are being loaded as angularAMD.service(...), so if it is also angularAMD.run(...), you need to sequence these not to conflict with each other, right?

F1LT3R commented 8 years ago

+1 for adding config support