【问题标题】:decode a html in typeScript angular 2在 typeScript angular 2 中解码 html
【发布时间】:2017-04-12 20:21:18
【问题描述】:

我从后端获取了一个编码 html,但我无法对其进行解码。

我尝试使用 decodeURIComponent 和 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

我曾经在 Jquery 中使用 document.getElementById("aux").innerHTML = $('').html(voucher).text(); 进行解码

但我不知道 Angular 2 是否有类似的东西。

谢谢

【问题讨论】:

  • 假设这是您要插入 DOM 的 HTML,您应该告诉服务器人员不要将 &amp;lt; 转义为 &amp;lt; 等。然后您可以使用 innerHTML 插入它。
  • innerHTML 现在是 innerHtml。

标签: html angular ionic2


【解决方案1】:

也许您需要一些指令,例如 [innerHtml]。请使用 trythis 示例:

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

还有var_string = "&lt;strong&gt;example&lt;/strong&gt;";

【讨论】:

  • 如果我像你们说的那样只使用 [innerHTML],我会得到“
    ”。我需要先解码,然后才能使用 InnerHTML
  • 也许你可以使用 decodeURIComponent。像这样: var uri_dec = decodeURIComponent(var_html_string);这是一个例子 -> w3schools.com/code/tryit.asp?filename=FA0TR4JH7GKL
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-14
  • 2018-10-02
  • 1970-01-01
  • 1970-01-01
  • 2016-11-27
相关资源
最近更新 更多