Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 888
doubledriscoll Avatar asked Oct 12 '12 00:10

doubledriscoll


1 Answers

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']);

http://docs.angularjs.org/api/angular.Module for all available module methods (you're probably only interested in .run() and .config())

like image 190
Andrew Joslin Avatar answered Sep 28 '22 10:09

Andrew Joslin