5

I'm getting from the back-end an encode html but I can't decode it.

I tried with decodeURIComponent and decodeURI.

I got from server='
"<table style="background-color: white;">
    <tbody>
        <tr>
            <td>
                    <div id="voucher">
                        <table>
                            <tr>
                                <td colspan="1" class="normal-left">ID:</td>
                                <td colspan="3" class="normal-left">ce203c7c804c4f258947adf3d63b2d7d</td>
                            </tr>
                        </table>
                    </div>
                </div>
            </td>
        </tr>
    </tbody>
</table>"
' 

// This is my HTML

<ion-content padding>
<ion-list>
  <ion-item>
    <span [innerHtml]="aux"></span>
  </ion-item>
  </ion-list>
</ion-content>

And this is the result

I used to decode in Jquery with document.getElementById("aux").innerHTML = $('').html(voucher).text();

But I don't know if Angular 2 has something similar.

Thanks

Javier Perez
  • 158
  • 1
  • 8
  • Assuming this is HTML that you want to insert into the DOM, you should tell the server guys not to escape `<` as `<` etc. Then you can just insert it using `innerHTML`. –  Nov 29 '16 at 03:54
  • innerHTML is now innerHtml. – Hadrien TOMA Nov 29 '16 at 07:38

1 Answers1

6

Maybe you need some directives, such as [innerHtml]. Please to use try this example:

 <div [innerHTML]="var_string"></div>

and the var_string = "<strong>example</strong>";

Community
  • 1
  • 1
Celso Agra
  • 1,389
  • 2
  • 15
  • 37
  • If I use just [innerHTML] as you guys say I'll get "
    ". I need to decode first and then I will be enable to use InnerHTML
    – Javier Perez Nov 29 '16 at 15:44
  • Maybe you can use decodeURIComponent. Like this: var uri_dec = decodeURIComponent(var_html_string); Here is an example -> http://www.w3schools.com/code/tryit.asp?filename=FA0TR4JH7GKL – Celso Agra Nov 30 '16 at 00:24