2016-11-08 144 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']);