I have N angular modules. One of them it is the root container that bootstrapped on and exists whole page life cycle. All other N-1 are games that nested inside of the page and need to be loaded dynamically and unloaded (How to unload angularjs modules) as well.
.------------------.
|Container |
| .----------. |
| |Game | |
| | | |
| | | |
| `----------` |
`------------------`
Each game - is the same way angular-module that has as a dependency main container to do some API interaction.
After some experiments I've found that in Angularjs 1.1.5 nested modules almost(!) works right: http://plnkr.co/edit/kJao7o
But with new one Angularjs (1.2.0-rc2) is broken: http://plnkr.co/edit/ZyhbRu
This example still raises exception:
Error: Argument 'GameCtrl' is not a function, got undefined
I've tried to use ng-include to prevent auto-injection from AngularJS. But still have same problem (http://plnkr.co/edit/EM1MbB);
I know that it's impossible to use the nested ng - app on the same page http://docs.angularjs.org/api/ng.directive:ngApp
But how it is possible to use more than one nested angular modules on the same page (with its own controllers)?
And I don't know is it just was temporary bug or Angular team decide to avoid of nested modules. Is there anybody know something about that?
Or, if using modules for such issue is bad idea - what is the best decision for that?
An AngularJS module defines an application. The module is a container for the different parts of an application. The module is a container for the application controllers. Controllers always belong to a module.
Angular 2 Modules Nesting modulesModules can be nested by using the imports parameter of @NgModule decorator.
Nested Controllers: AngularJS allows using nested controllers. It means that you have specified a controller in an HTML element which is a child of another HTML element using another controller.
Modules with grouped test functions are used to define nested modules. QUnit run tests on the parent module before going deep on the nested ones, even if they're declared first. The beforeEach and afterEach callbacks on a nested module call will stack in LIFO (Last In, First Out) Mode to the parent hooks.
Oh! I just realized you idea. Actually you have incorrect understanding of Angular building components.
They doesn't have any relation to the modules on a markup, it's just a logical unit in your app.
Look at the official developer guide for more details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With