【问题标题】:Display html tags in angular template, don't render it在角度模板中显示 html 标签,不要渲染它
【发布时间】:2020-07-29 22:40:23
【问题描述】:

我想在 Angular 应用中写一些关于 html 标签的信息。我无法弄清楚如何在不呈现 html 的情况下在 Angular 模板中显示 html 标签。

例如

component.html

 <p> you can use <code> </p> </code> tag for paragraph </p>

预期:

you can use &lt;/p&gt; tag for paragraph

一种方法是在组件中创建变量并将其插入到视图中。但我不认为只为单个标签文本创建这么多变量。

例如 component.html

 <p> you can use <code> {{myPTag}} </code> tag for paragraph </p>

component.ts

... 
myPTag = "</p>"
...

【问题讨论】:

    标签: javascript html angular


    【解决方案1】:

    不要使用 '' 而是使用 &amp;lt;&amp;gt;

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-10-29
      • 1970-01-01
      • 2015-09-12
      • 2014-05-17
      • 1970-01-01
      • 2017-10-25
      • 1970-01-01
      • 2017-02-11
      相关资源
      最近更新 更多