Ben Aston Ben Aston - 2 months ago 11
AngularJS Question

Make an object available when bootstrapping an AngularJS app?

When bootstrapping an AngularJS app is it possible to configure the root scope object before any directive in the application is instantiated?

I want to supply an object an make it available to the application via the root scope (or even the injector).

var myObject = { /* stuff */ };
// Can I make `myObject` available to the application via AngularJS?
angular.bootstrap(rootDomNode, [APPLICATION_NAME]);


Or should I bypass AngularJS for this and stick it in some shared object?

Answer

You can use the module's .run() function to do that:

angular.module('myModule', []).
   .run(function($rootscope) { // instance-injector
      // Modify your rootscope here
   });
Comments