我有一个 Angular 片段,我想在其中将字符串转换为 HTML 对象。
`<div class="row">
<label class="col-md-4 info_text">Remarks<span>:</span></label> <label
class="col-md-8 fieldValue">{{initialTableInfo.comments}}
</label>
</div>`
initialTableInfo.comments
具有值 <b>someText</b>
.它正在按原样打印。我希望将“someText”打印为 someText 而不是 <b>someText</b>
.
最佳答案
您可以为 Angular 使用 $sce 参数。
module.controller('myctrl', ['$scope', '$http', '$sce',function($scope, $http, $sce) {
$scope.initialTableInfo.comments = $sce.trustAsHtml("<b>Some Text<b>");
}]);
并在您的 HTML 中使用 ng-bind-html
<label class="col-md-8 fieldValue" ng-bind-html="initialTableInfo.comment"> </label>
关于javascript - 在标签 AngularJS 中将字符串转换为 html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44582966/