[英]Why AngularJS prints double quotation in HTML
With AngularJs, I am trying to display currency exchange with image. 使用AngularJs,我试图用图像显示货币兑换。 Here is my Razor code below.
这是我的Razor代码。
<span ng-controller="CurrencyController">
<span ng-bind="currencies"></span>
</span>
and I am sending the below text from controller 我从控制器发送以下文字
string text = "Dollar : 1.7 <img src=\"~/Images/Currency/up.png\">";
when the HTML is rendered, I took a look at the source in Chrome, and I saw the HTML below... 当HTML呈现时,我看了Chrome中的源代码,我看到下面的HTML ...
<span class="ng-binding">
"Dollar: 1.7 <img src="~/Images/Currency/down.png">"
</span>
Why is the rendered text in HTML is surrounded with double quotation? 为什么HTML中的渲染文本被双引号括起来? how can I fix this?
我怎样才能解决这个问题?
You should be using ng-bind-html, as stated in the docs, is the directive used to render html. 您应该使用ng-bind-html,如文档中所述,是用于呈现html的指令。 ng-bind should only be used if you cant to render a simple html text node.
只有在无法呈现简单的html文本节点时才应使用ng-bind。
So, your code should look like this: 所以,你的代码应该是这样的:
<span ng-controller="CurrencyController">
<span ng-bind-html="currencies"></span>
</span>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.