0

我正在使用 TinyMCE 对用户保存到数据库的内容进行样式设置,用户可以保存的示例如下:

<ol><li><em>This</em> is a <span style="text-decoration: underline;" data-mce-style="text-decoration: underline;">HTML</span> email that <strong><span style="font-family: 'times new roman', times;">should</span></strong> <span style="font-family: tahoma, arial, helvetica, sans-serif;">contain</span> different <span style="font-family: arial, helvetica, sans-serif;">fonts</span> in weights with lists and links...</li></ol>

我目前正在使用ng-bind-html在我的视图中显示此 HTML 内容,但是,它似乎正在剥离内联样式。这是我的浏览器来源:

<ol><li><em>This</em> is a <span>HTML</span> email that <strong><span>should</span></strong> <span>contain</span> different <span>fonts</span> in weights with lists and links...</li></ol>

有没有办法可以将这些内联样式保留在视图中?

4

2 回答 2

1

您可以尝试将您的 HTML 标记为受信任,并传入$sce,如下所示:

yourApp.controller('someCtrl', ['$scope', '$sce', function($scope, $sce) {      
  $scope.some_html = $sce.trustAsHtml(some_html_content);
}]);
于 2015-06-15T10:12:16.243 回答
0

如果您使用的是 Angular 1.2+,您必须这样做:

$scope.htmlToBind = $sce.trustAsHtml(yourHtml);

有关更多详细信息,请参阅文档

于 2015-06-15T10:10:21.050 回答