如何使用 ng-bind-html 但禁用标签 <h1>、<b>... AngularJS

How to use ng-bind-html but disable tag <h1>, <b>... AngularJS

我使用 ng-bind-html 并显示成功数据,但我只想显示文本,而不是显示带有样式的数据,因为它破坏了我的布局:

数据为内容注释:<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>

简短回答:您可以将 css class 应用于 div,重置 html 标记格式行为以覆盖它。例如:

<p class="ignore-html-tags" ng-bind-html="note.content.substr(0, 130) + '...' | to_trusted"></p

在你的 css 中:

.ignore-html-tags * {
  font-size: 10px !important;
  font-weight: normal !important;
  /* any other style overwrite */
}