angularAMD icon indicating copy to clipboard operation
angularAMD copied to clipboard

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

Open mpiasta-ca opened this issue 10 years ago • 5 comments

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.

mpiasta-ca avatar Dec 16 '14 17:12 mpiasta-ca

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.

marcoslin avatar Dec 16 '14 18:12 marcoslin

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(...)
    });
  });
});

mpiasta-ca avatar Dec 18 '14 23:12 mpiasta-ca

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.

marcoslin avatar Dec 19 '14 10:12 marcoslin

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?

mpiasta-ca avatar Feb 17 '15 20:02 mpiasta-ca

+1 for adding config support

F1LT3R avatar Nov 24 '15 20:11 F1LT3R