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

2
  • Assuming this is HTML that you want to insert into the DOM, you should tell the server guys not to escape < as &lt; etc. Then you can just insert it using innerHTML. Commented Nov 29, 2016 at 3:54
  • innerHTML is now innerHtml. Commented Nov 29, 2016 at 7:38

1 Answer 1

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>";

Sign up to request clarification or add additional context in comments.

2 Comments

If I use just [innerHTML] as you guys say I'll get "<table><tr></tr></table>". I need to decode first and then I will be enable to use InnerHTML
Maybe you can use decodeURIComponent. Like this: var uri_dec = decodeURIComponent(var_html_string); Here is an example -> w3schools.com/code/tryit.asp?filename=FA0TR4JH7GKL

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.