Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert String to html in label AngularJS

I have an angular snippet in which I want to convert string to HTML object.

 `<div class="row">
     <label class="col-md-4 info_text">Remarks<span>:</span></label> <label
      class="col-md-8 fieldValue">{{initialTableInfo.comments}}
     </label>
    </div>`

The initialTableInfo.comments has the value <b>someText</b>. It is getting printed as it is. I want "someText" to be printed as someText instead of <b>someText</b>.

like image 801
nit710 Avatar asked Nov 07 '25 09:11

nit710


1 Answers

You can use the $sce parameter for angular.

module.controller('myctrl', ['$scope', '$http', '$sce',function($scope, $http, $sce) {

$scope.initialTableInfo.comments = $sce.trustAsHtml("<b>Some Text<b>");

}]);

And in your HTML use ng-bind-html

<label class="col-md-8 fieldValue" ng-bind-html="initialTableInfo.comment"> </label>
like image 137
Alexi Coard Avatar answered Nov 10 '25 00:11

Alexi Coard



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!