ng-bind-html与bind-html-compile? [英] ng-bind-html vs bind-html-compile?

查看:79
本文介绍了ng-bind-html与bind-html-compile?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道ng-bind-html和bind-html-compile指令之间的区别.例如,我给了

I want to know the difference between ng-bind-html and bind-html-compile directives. For example I gave

<p style='color:red'>test<p> 

对ng-bind-html来说,这会剔除bind-html-compile所没有的样式.我可以知道何时应该使用每个指令.谢谢.

to ng-bind-html, this strips out the style where as bind-html-compile does not. May I know when each directive should be used. Thanks.

推荐答案

bind-html-compile 不是标准的Angular指令,它随模块

bind-html-compile is not a standard Angular directive, it comes with the module https://github.com/incuna/angular-bind-html-compile and it is used to compile binded data.To make it simple, it is equivalent to write html in your source code: it will be re-evaluated and if other directives are found, they will work as expected.

ng-bind-html 是标准指令(与Angular本身捆绑在一起),仅输出html字符串而无需编译.

ng-bind-html is a standard directive (bundled with Angular itself) and just output html strings without compiling it.

例如,如果您的控制器有一个带有纯html的变量,例如:

for example, if you controller has a variable with plain html, like in:

$scope.dataToDisplay = '<h1><strong>Title</strong></h1>';

然后您可以使用ng-bind-html.

如果您需要使用其他指令来注入包含html的变量,例如:

If you need to inject variables that contain html with other directives, such as:

$scope.dataToDisplay = '<h1 ng-show="showIfOtherVariable"><strong>Title</strong></h1>';

然后您需要上述模块.

这篇关于ng-bind-html与bind-html-compile?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆