NG-的bind-HTML VS {{插值}} [英] ng-bind-html vs {{interpolation}}

查看:263
本文介绍了NG-的bind-HTML VS {{插值}}的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的问题,有什么利弊?

That is my question, what are the pros and cons ?

在我的应用程序,我使用插值,但我得到这样的错误

In my app I am using interpolation but I get errors like this

{{:: sport.name}} - > NHL期货及放大器;放大器;道具

如果我用 NG-绑定-HTML

NG-绑定-HTML =sport.name - > NHL期货及放大器;道具

在这种情况下, NG-绑定-HTML 正在做我想要的。但是,是有什么错呢?

in this case ng-bind-html is doing what I want. But, is there something wrong with it ?

有其中一个比另一个更好呢?

Is there one better than the other ?

这样告诉我,我很开放的建议。

so tell me, I am open to suggestions.

推荐答案

其实NG绑定和NG绑定-HTML之间的主要区别是用例。
NG-绑定将只显示文本间$ P $的变量ptation但纳克绑定-HTML将跨preT在变量的HTML。

Actually the main difference between ng-bind and ng-bind-html is the usecase. ng-bind will just display the text interpretation of your variable but ng-bind-html will interpret the html in your variable.

让说,我们在你的范围有一个变量

Let say we have a variable in your scope

 $scope.myText = "<b>Hi</b>";

NG-绑定或{{}}将显示

ng-bind or {{}} would display

 <b>Hi</b>

NG-绑定-HTML将显示

ng-bind-html would display

你好

另外precision是NG绑定,HTML可以净化你的HTML,以prevent code注射液。

Another precision is that ng-bind-html can sanitize your html to prevent code injection.

这篇关于NG-的bind-HTML VS {{插值}}的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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