AngularJS: How to nest applications within an angular app

You can’t bootstrap a module inside another bootstrapped module. Bootstrapping compiles the view and binds a rootScope to it, 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.

You’re probably going to have to rethink your architecture. I think perhaps the word “module” or “app” as it pertains to Angular is a misnomer and is leading you down the wrong path.

Each “user installed app” in your application should probably really be controlled by a controller in your app module, or registered to a module referenced by your app module. So you wouldn’t be “starting up multiple apps”, you’d really just be starting one, referencing the other modules, then using Controllers from those modules to control parts of your view on the screen.

What you’d do is when a new “widget” was installed, you’re register it’s module file (.js) with the system, which would contain a controller named WidgetCtrl, then when your page loaded, you’d reference the widget’s module on your app module. From there it should be available for dynamic assignment to elements using ng-controller and/or ng-include.

I hope that makes sense.

Leave a Comment