我正在使用htmlspecialchars()将数据保存到mysql中。在使用htmlspecialchars_decode()获取数据并在Angular中显示之前获取输出时。但与其解释HTML代码,不如将其显示为文本。
数据库中的数据
<p class="fr-tag"><span>test</span></p>
在htmlspecialchars_decode()之后显示代码
<p class="fr-tag"><span>test</span></p>
如下显示从数据库到div的输出
<div *ngIf="product.pdescription" class="mt-2 product-description">{{product.pdescription}}</div>
我也尝试使用html_entity_decode,但没有帮助。
下面是浏览器的屏幕截图
为了使其正常工作,您应该使用innerHTML或externalHTML绑定:
<div *ngIf="product.pdescription" ... [innerHTML]="product.pdescription"></div>
但是要注意一些limitations