添加指令模块后,引导和应用上的动态内容 [英] Add directive to module after bootstrap and applying on dynamic content
问题描述
我有哪里我使用boostraping angularjs
I have a web page with a module defined (myModule) where I'm boostraping angularjs using
angular.bootstrap(element,[myModule.name]);
一个点击按钮后,我添加动态HTML和使用编译
After the click of a button, I add dynamic html and compile using
$compile('<my-element data="data"></my-element>',$scope.$new());
该指令通过添加
myModule.directive('myElement',function(){});
问题是,当我打电话引导前添加指令,编译$结束了正确处理我的指令。但是,如果指令调用引导后添加,$编译并没有做任何事情来我的HTML。它只是增加了类NG-范围,它与指令/标签不被处理。
The problem is when I add the directive before calling bootstrap, $compile ends up correctly processing my directive. However, if the directive is added after calling bootstrap, $compile does not do anything to my html. It just adds the class ng-scope to it and the directive/tag is not processed.
在我的情况下,并非所有的指令都可以被引导被调用之前加载。在这里我呼吁引导加载后指令的情况下,我怎么在页面中使用它?
In my case, not all the directives will be loaded before bootstrap is called. In the case where I load directives after calling bootstrap, how do I get to use it within the page?
感谢。
编辑:
只是为了澄清。所有的指令都是动态加载。这些我以前的引导做工精细加载。我的那些引导加载失败后。当我换装的指示,我可以在相同的结果,所以它不是指令,但似乎是引导后,新增加的指令似乎并没有生效。
Just to clarify. All directives are loaded dynamically. Those I load before bootstrapping work fine. Those I load after bootstrapping fails. When I swap the directives loaded, I can the same result so it is not the directives but appears to be that after bootstrapping, newly added directives does not seem to take effect.
推荐答案
与注册懒惰控制器或指令的事情是,你必须弄个 $ controllerProvider 的并 $ compileProvider 的分别。
The thing with registering lazy controller or directives is that you have to get hold of $controllerProvider and $compileProvider respectively.
可以只在配置阶段,所以你必须保持引用,直到您装入控制器/指令完成的。
It can be done only during configuration phase so you have to keep the references until you load the controllers/directives.
最近我工作的控制器的延迟加载,今天我已经添加了支持的指令,在这里看看我的code:
Lately I was working on lazy loading of the controller, today I've added support for directives, check out my code here:
<一个href=\"https://github.com/matys84pl/angularjs-requirejs-lazy-controllers\">https://github.com/matys84pl/angularjs-requirejs-lazy-controllers/
特别是这个模块<一个href=\"https://github.com/matys84pl/angularjs-requirejs-lazy-controllers/blob/master/app/js/utils/lazy-directives.js\">lazy-directives.js
particularly this module lazy-directives.js
注意:我使用的 RequireJS 的在我的项目,但我的应用解决方案的 yepnope 的应该是很容易的。
NOTE: I use RequireJS in my project, however applying my solution to yepnope should be quite easy.
这篇关于添加指令模块后,引导和应用上的动态内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!