嵌套模块在AngularJS [英] the Nested Modules in AngularJS
问题描述
我有N个角度模块。其中之一是根容器自举上存在整个页面生命周期。所有其它N-1个是游戏,嵌套在页面内和需要被动态加载和卸载(如何卸载angularjs模块)为好。
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 | |
| | | |
| | | |
| `----------` |
`------------------`
详细信息
每个游戏 - 是具有作为一个依赖主容器以同样的方式角模块做了一些API的交互
Details
Each game - is the same way angular-module that has as a dependency main container to do some API interaction.
一些实验,我发现,在Angularjs 1.1.5嵌套模块几乎的作品的权利后(!):
http://plnkr.co/edit/kJao7o
After some experiments I've found that in Angularjs 1.1.5 nested modules almost(!) works right: http://plnkr.co/edit/kJao7o
但随着新的Angularjs(1.2.0-RC2)被打破:
http://plnkr.co/edit/ZyhbRu
But with new one Angularjs (1.2.0-rc2) is broken: http://plnkr.co/edit/ZyhbRu
这个例子仍然引起异常:
This example still raises exception:
错误:参数'GameCtrl不是一个函数,得到了不确定
Error: Argument 'GameCtrl' is not a function, got undefined
我试着使用的 NG-包括的以prevent从AngularJS自动注入。但仍然有同样的问题( http://plnkr.co/edit/EM1MbB );
I've tried to use ng-include to prevent auto-injection from AngularJS. But still have same problem (http://plnkr.co/edit/EM1MbB);
我知道这是不可能的,使用嵌套纳克 - 在同一页上的应用
<一href=\"http://docs.angularjs.org/api/ng.directive:ngApp\">http://docs.angularjs.org/api/ng.directive:ngApp
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?
- 的名称的范围隔离(以避免名称的冲突)。我可以保证,任何两个或多个未来的游戏将不会使用相同的名称ctrls监视或东西;
- 要卸载模块(我不知道是AngularJs有可能 - 但我要去尝试);
推荐答案
哦!我才意识到你的想法。
其实你有角的建筑构件的不正确的认识。
Oh! I just realized you idea. Actually you have incorrect understanding of Angular building components.
- 角模块仅仅是控制器的指令,工厂等的逻辑封装
例如,你将不得不模块主和几个子模块moduleA'和'moduleB
他们没有任何关系上标记的模块,它在你的应用程序只是一个逻辑单元。
They doesn't have any relation to the modules on a markup, it's just a logical unit in your app.
- 在您的例子中,你的意思是有希望的范围即可。您可能有几个在范围你的应用程序,它们可以inhireted或有孩子。在这种情况下,你可以加载或卸载创建范围的实体
- In your example you hopefully mean scopes. You may have several scopes in your app and they can be inhireted or have children. And in this case you can load or unload entity that created the scope
看href=\"http://docs.angularjs.org/tutorial\" rel=\"nofollow\">官方开发指南更多细节
Look at the official developer guide for more details.
这篇关于嵌套模块在AngularJS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!