Reputation: 21074
The angular documentation for the angular.bootstrap(...)
method says the second argument is:
...an array of modules to load into the application. Each item in the array should be the name of a predefined module or a (DI annotated)
I had never seen Angular code which passes a more than one module in to be boostrapped to the same DOM element... Why would you want to do that? Angular tutorials don't provide an example. So I found this example on StackOverflow. This example bootstraps both peopleApp
and thermostatApp
to the document:
angular.bootstrap(document, ['peopleApp','thermostatApp']);
What happens if those apps have the same name for a controller? Like MyCtrl
? Which definition is respected?
How is boostrapping multiple modules; different than creating a new ConsolidatedModule
, which has dependencies to the one or more modules you would've boostrapped, and then just bootstrapping the single ConsolidatedModule
? i.e.
angular.module('ConsolidatedModule', ['peopleApp', 'thermostatApp']);
angular.bootstrap(document, ['ConsolidatedModule'])
To be clear, I'm not talking about bootstrapping separate apps to separate DOM elements. (also shown here)
Other anecdotal evidence that makes me confused about this:
You can't shouldn't (?) bootstrap an app within another already bootstrap'd app (... because
"traversing it's way through the DOM and setting up scope bindings and executing directive linking functions all the way through. If you do that twice, you're going to run into problems."
-- and yet, bootstrapping the same element with two modules won't run into problems?)
In Angular2, platformBrowserDynamic.bootstrapModule(...)
is singular; implies it only accepts a single argument ( I couldn't find the API), so I'm even more confused what it means in angular 1.* to bootstrap multiple modules to the same DOM node.
Upvotes: 2
Views: 1916
Reputation: 222494
There's no difference between
angular.module('ConsolidatedModule', ['peopleApp', 'thermostatApp']);
angular.bootstrap(document, ['ConsolidatedModule'])
and
angular.bootstrap(document, ['peopleApp', 'thermostatApp'])
except unneeded ConsolidatedModule
module that is created in the first case. Only 1 injector is created, and bootstrapping with multiple modules has nothing to do with multiple bootstrapping.
The second argument allows to provide a list of modules dynamically. I.e.
const modulesList = ['foo'];
if (ENV_BAR)
modulesList.push('bar');
angular.bootstrap(document, modulesList);
Upvotes: 1