我试图在绑定文本中创建角度识别标记:

<p *ngFor="let explanation of explanations">{{explanation.htmlText}}</p>

解释对象的外观如下:
{
   "id": 1,
   "htmlText": "This is a dummy text to test <a>links</a>. Looks like it doesn't work."
}

但结果是这样的:
javascript - 如何使Angular识别绑定(bind)内的HTML?-LMLPHP
有没有办法让它识别<a>标记并在<a>元素中显示实际的<p>元素?

最佳答案

使用innerHTML因为传统的插值无法工作,

<p *ngFor="let explanation of explanations" [innerHTML]="explanation.htmlText"></p>

希望这有帮助!

07-24 09:44