angular-ivh-treeview 中的自定义标签允许 HTML
Custom Label in angular-ivh-treeview that allows for HTML
我正在使用 https://github.com/ivantage/angular-ivh-treeview/blob/master/docs/templates-and-skins.md#tree-layouts
并且在标签内部或使用自定义节点字段绑定到 ng-bind-html 时遇到问题。所以我尝试制作一个自定义指令来替换标签字段,但我似乎无法让它工作。
有什么方法可以使用 ng-sanitize 将标签绑定为 html,以便我可以将 html 标记放入标签中?
如果您的标签中已经嵌入了 HTML,最简单的做法是使用 ivhTreeviewBfs
服务遍历您的树,并使用 $sce.trustAsHtml
明确信任每个节点的标签.然后您可以根据需要在模板中使用 ng-bind-html="trvw.lable(node)"
。
这里有一个演示来说明:http://jsbin.com/bogoyu/2/edit?js,output
请注意,也可以根据节点属性向模板添加条件(即 ng-class="{fancy: node.foo = '...'}" 等.) 如果你不想把 html 放在你的标签中。
除了 Justin 的出色回答之外,您还可以使用 angular 的 ngSanitize
模块来 'sanitize' html。
只需包含 angular-sanitize 并将 ngSanitize
作为应用程序模块的依赖项。例如:
var app = angular.module("myApp", ['ngSanitize']);
使用 ng-bind-html
绑定的范围变量会自动清理。无需遍历树或使用$sce
服务
我正在使用 https://github.com/ivantage/angular-ivh-treeview/blob/master/docs/templates-and-skins.md#tree-layouts 并且在标签内部或使用自定义节点字段绑定到 ng-bind-html 时遇到问题。所以我尝试制作一个自定义指令来替换标签字段,但我似乎无法让它工作。
有什么方法可以使用 ng-sanitize 将标签绑定为 html,以便我可以将 html 标记放入标签中?
如果您的标签中已经嵌入了 HTML,最简单的做法是使用 ivhTreeviewBfs
服务遍历您的树,并使用 $sce.trustAsHtml
明确信任每个节点的标签.然后您可以根据需要在模板中使用 ng-bind-html="trvw.lable(node)"
。
这里有一个演示来说明:http://jsbin.com/bogoyu/2/edit?js,output
请注意,也可以根据节点属性向模板添加条件(即 ng-class="{fancy: node.foo = '...'}" 等.) 如果你不想把 html 放在你的标签中。
除了 Justin 的出色回答之外,您还可以使用 angular 的 ngSanitize
模块来 'sanitize' html。
只需包含 angular-sanitize 并将 ngSanitize
作为应用程序模块的依赖项。例如:
var app = angular.module("myApp", ['ngSanitize']);
使用 ng-bind-html
绑定的范围变量会自动清理。无需遍历树或使用$sce
服务