AngularJS : How to get the uncompiled transclude content of a directive

标签 angularjs angularjs-directive angularjs-ng-transclude

我正在尝试使用指令的嵌入内容(指令的原始内容,而不是模板)作为网格中一行的 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/

相关文章:

javascript - 为什么没有为指令中的 ng-options 设置空白选项

javascript - AngularJS 指令嵌套 ng-transinclude 内的隔离范围

javascript - angularjs 模块和 Controller 不工作

javascript - 在 Angular Directive(指令)中将焦点设置到文本区域

javascript - 如何使用 ng-hide 和 ng-repeat 根据条件显示元素

AngularJS - 从自定义指令将参数从 ng-repeat 传递到 Controller

javascript - 临时局部变量的 Angular 指令

javascript - 在模板中非法使用 ngTransclude 指令!手动进行嵌入时

javascript - 通过使用字符串变量作为作用域名称来引用 $scope,例如$范围。[stringVar]

javascript - 使用另一个过滤器传递的参数应用 Angular 过滤器