2016-11-08 234 views
2

我在JSON内部有一些值,如1000, 2000, <b>3000</b>, <4000>, <b>5000</b>作为API响应。我想在一个表内呈现这个响应。所以我尝试了ng-bind-html。但它只显示具有3000,5000标签的值。我想显示所有值,1000,2000,4000作为一个纯字符串和3000,5000 BOLD /或任何其他HTML标记。从字符串呈现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> 
+0

SE http://stackoverflow.com/questions/22536477/rendering-dynamic-htmlangularjs-content-content-content-content-content-after-ajax-call-in-angularjs –

回答

1

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

你可以找到更多的细节here

一定要确保你净化你的字符串,以防止安全漏洞

+0

注入Sanitize后,ng-bind-html给了我与$ sce.trustAsHtml(item.amount)相同的结果;意味着它只显示具有HTML标签的值,并且ng-bind-html-unsafe不会给我任何价值 –

1

可以使用NG-的sanitize模块相同 - see here

var app = angular.module("myApp", ['ngSanitize']);