0

I used ng-bind-html and show success data, but I want to show only text, not show data with style , because it ruined my layout:

enter image description here

Data is content's notes: <h1>some text....</h1>

My filter:

var myApp = angular.module("myModule", []);
myApp.filter('to_trusted', ['$sce', function ($sce) {
    return function (text) {
        return $sce.trustAsHtml(text);
    };
}]);

My view:

<p ng-bind-html="note.content.substr(0, 130) + '...' | to_trusted"></p>
1
  • You really shouldn't arbitrarily trust content sent from other sites unless you are filtering it out to make sure it doesn't have malicious scripts being sent into your program. Not sure about stripping out the html tags client side but server side could use unfluff github.com/ageitgey/node-unfluff Commented Nov 17, 2017 at 11:28

1 Answer 1

1

Short answer: You can apply a css class to the div, resetting html tag formatting behavior overriding it. For example:

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

And in your css:

.ignore-html-tags * {
  font-size: 10px !important;
  font-weight: normal !important;
  /* any other style overwrite */
}
Sign up to request clarification or add additional context in comments.

3 Comments

It's not working :(. Html: <p class="ignore-html-tags"><h1>aaa</h1></p. style of class ignore-html-tags not work with <h1> Demo: jsfiddle.net/lion5893/2t5q0fhc
@NamLêQuý could you please post a jsfiddle or a codepen snippet? I'll help you directly on the code, then
thanks your help, i fixed. i use .ignore-html-tags * {...}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.