2

I have some values as amount like 1000, 2000, <b>3000</b>, <4000>, <b>5000</b> inside JSON as an API response. I want to render this response inside a table. So I tried ng-bind-html. BUT it is showing only the value which are having tags like 3000,5000. I want to show all values , 1000,2000,4000 as a plain string and 3000,5000 in BOLD/or any other HTML tag.

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

On HTML side, I have something like this

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

3 Answers 3

1

You can use ng-bind-html and ng-bind-html-unsafe for this. But please be mindful of the security concerns here.

You can find more details here

Do make sure you sanitize your strings, to prevent security vulnerabilities

Sign up to request clarification or add additional context in comments.

1 Comment

After injecting Sanitize, ng-bind-html is giving me same result as $sce.trustAsHtml(item.amount); means it is only showing the value which has HTML tag AND ng-bind-html-unsafe is not giving me any value
1

First of all you need to download the ng-sanitize js https://docs.angularjs.org/api/ngSanitize

and then inject ng-sanitize to angular module. then you can use ng-bind-html and ng-bind-html-unsafe

Comments

1

you can use ng-sanitize module for the same - see here

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.