Javascript 从字符串呈现html标记

Javascript 从字符串呈现html标记,javascript,jquery,angularjs,Javascript,Jquery,Angularjs,作为API响应,JSON中有一些值,如amount,比如1000、2000、3000、5000。我想在一个表中呈现这个响应。所以我尝试了绑定html。但它只显示有30005000这样标签的值。我想显示所有值,100020004000为普通字符串,30005000为粗体/或任何其他HTML标记 angular.forEach($scope.arr2.test,function(item) $scope.res=$sce.trustAsHtml(item.amount); return $s

作为API响应,JSON中有一些值,如amount,比如
1000、2000、3000、5000
。我想在一个表中呈现这个响应。所以我尝试了绑定html。但它只显示有30005000这样标签的值。我想显示所有值,100020004000为普通字符串,30005000为粗体/或任何其他HTML标记

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 html
ng bind html unsafe
。但请注意这里的安全问题

你可以找到更多的细节


请确保对字符串进行清理,以防止安全漏洞

首先,您需要下载ng sanitize js

然后将ng消毒液注入角度模块。
然后,您可以使用ng bind html和ng bind html不安全

您可以使用ng sanitize模块进行相同的操作-


se在注入Sanitize后,ng bind html给出了与$sce.trustAsHtml(item.amount)相同的结果;这意味着它只显示带有HTML标记的值,而ng bind HTML不安全并没有给我任何值
 var app = angular.module("myApp", ['ngSanitize']);