gpt4 book ai didi

javascript - 使用 Angular 将文本呈现为 html

转载 作者:搜寻专家 更新时间:2023-10-31 08:07:31 24 4
gpt4 key购买 nike

我正在尝试使用 ng-bind 作为 docs show 将文本呈现为 html

<div ng-bind-html="text"></div>

问题是 Angular 删除了 style 属性并呈现这个:

"<mark style='background-color:#FF9DFF;'>APPLE</mark>."

为此:

<mark>APPLE</mark>

如何呈现为 html 并保持样式?我正在使用 Angular 版本 1.2.6

最佳答案

您可以在 Controller 中执行 ng-bind-html 时尝试此功能

$sce.trustAsHtml('myHTML'); //$sce would be the parameter with $scope in module

希望这能奏效

$NgSanitizeDocs

关于javascript - 使用 Angular 将文本呈现为 html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22408363/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com