【发布时间】:2017-11-17 11:22:23
【问题描述】:
我使用 ng-bind-html 并显示成功数据,但我只想显示文本,而不是显示带有 style 的数据,因为它破坏了我的布局:
数据是内容的注释:<h1>some text....</h1>
我的过滤器:
var myApp = angular.module("myModule", []);
myApp.filter('to_trusted', ['$sce', function ($sce) {
return function (text) {
return $sce.trustAsHtml(text);
};
}]);
我的看法:
<p ng-bind-html="note.content.substr(0, 130) + '...' | to_trusted"></p>
【问题讨论】:
-
您真的不应该任意信任从其他站点发送的内容,除非您将其过滤掉以确保它没有被发送到您的程序中的恶意脚本。不确定是否要去掉客户端的 html 标签,但服务器端可以使用 unfluff github.com/ageitgey/node-unfluff