Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why AngularJS prints double quotation in HTML

With AngularJs, I am trying to display currency exchange with image. Here is my Razor code below.

<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...

<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? how can I fix this?

like image 697
Arif YILMAZ Avatar asked Jul 31 '26 10:07

Arif YILMAZ


1 Answers

You should be using ng-bind-html, as stated in the docs, is the directive used to render html. ng-bind should only be used if you cant to render a simple html text node.

So, your code should look like this:

<span ng-controller="CurrencyController">
   <span ng-bind-html="currencies"></span>
</span>
like image 162
Daniel Santiago Avatar answered Aug 01 '26 23:08

Daniel Santiago



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!