doubledriscoll doubledriscoll - 8 months ago 19
AngularJS Question

How to configure an AngularJS app at load time?

I want to do something like this (but obviously not this exactly, because this function doesn't work this way)

angular.bootstrap( $("#myelement"), ['myModule'], {foo: bar} );

I want to pass in a configuration object, since we may want to have more than one instance of the app on a page, with different settings, etc. All I can think of are ugly workarounds. I'm thinking the best thing would be to override an "Options" service of my own making, but I still can't figure out the proper way to do that (tersely).

Thanks in advance!


How about you try something like this:

angular.module('configFoo', []).run(function() {});

angular.module('configBar', []).run(function() {});

angular.bootstrap(myEl, ['myModule', 'configFoo']);

angular.bootstrap(myOtherEl, ['myModule', 'configBar']); for all available module methods (you're probably only interested in .run() and .config())