angularAMD
angularAMD copied to clipboard
How to setup an app.config(...)?
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.
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.
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(...)
});
});
});
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.
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?
+1 for adding config support