我正在尝试使用指令的嵌入内容(指令的原始内容,而不是模板)作为网格中一行的 HTML 模板。
<grid attrs="...">
<action-column-template>...(html I need)...</action-column-template>
</grid>
这个想法是我需要 action-column-template 的原始 HTML(未编译,未绑定(bind)到任何范围)。
我不控制每一行的生成,所以我不能使用 transclude(rowScope) 手动将该操作模板绑定(bind)到每一行的范围。我只需要它作为纯 html (即“{{ }}”s 和内部指令不变)。
从链接函数运行 transclude() fn 给了我被嵌入的内容,但绑定(bind)到一个范围并扩展了内部指令。并且 compile 函数的 tElem 参数的 html() 返回指令模板的 HTML,而不是要转入的内容。
所以问题是:我可以在编译、 Controller 、preLink 或 postLink 函数中将指令的内容转换为未编译的 HTML 吗?
谢谢你。
最佳答案
设置 terminal: true
,并手动编译指令。
关于AngularJS : How to get the uncompiled transclude content of a directive,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26424220/