ng-bind-html vs bind-html-compile? [英] ng-bind-html vs 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 指令,它带有模块 https://github.com/incuna/angular-bind-html-compile 用于编译绑定数据.为简单起见,相当于在你的源代码中编写html:它会被重新评估,如果找到其他指令,它们会按预期工作.
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 vs bind-html-compile?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!