gpt4 book ai didi

javascript - 从字符串渲染 html 标签

转载 作者:行者123 更新时间:2023-11-29 19:09:08 31 4
gpt4 key购买 nike

我有一些值,如 1000, 2000, <b>3000</b>, <4000>, <b>5000</b>在 JSON 中作为 API 响应。我想在表格中呈现此响应。所以我尝试了 ng-bind-html。但它仅显示具有 3000,5000 等标签的值。我想以粗体/或任何其他 HTML 标记显示所有值,1000,2000,4000 作为纯字符串和 3000,5000。

angular.forEach($scope.arr2.test,function(item)
$scope.res=$sce.trustAsHtml(item.amount);
return $scope.res;
});

在 HTML 方面,我有这样的东西

<td id="price" class="edit" ng-repeat="pro in d.procedure" ng-bind-html="valueCheck(d._id,pro._id,hos._id)"></td>

最佳答案

您可以为此使用 ng-bind-htmlng-bind-html-unsafe。但请注意这里的安全问题。

您可以找到更多详细信息 here

一定要清理你的字符串,以防止安全漏洞

关于javascript - 从字符串渲染 html 标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40480429/

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