我正在尝试使用ng-bind将文本渲染为HTML,如文档所示
<div ng-bind-html="text"></div>
问题在于Angular会移除style属性并呈现如下内容:
"<mark style='background-color:#FF9DFF;'>APPLE</mark>."
转换为:
<mark>APPLE</mark>
如何将HTML呈现并保留样式? 我正在使用Angular版本1.2.6。
我正在尝试使用ng-bind将文本渲染为HTML,如文档所示
<div ng-bind-html="text"></div>
问题在于Angular会移除style属性并呈现如下内容:
"<mark style='background-color:#FF9DFF;'>APPLE</mark>."
转换为:
<mark>APPLE</mark>
ng-bind-html
时,可以尝试使用此函数。$sce.trustAsHtml('myHTML'); //$sce would be the parameter with $scope in module
希望这能奏效。
<div ng-bind-html="deliberatelyTrustDangerousSnippet()"></div>
pk.controller("createBlog", function($scope, $sce){
//ace needs to be injected in the controller.
$scope.deliberatelyTrustDangerousSnippet = function() {
return $sce.trustAsHtml($scope.htmlcontent); //html content is th binded content.
};
})