skip to Main Content

I want to display data from database (using PHPMYADMIN). The data which I want to display stored using ng2-ckeditor (Angular 6). So when it gives result it also shows the html tags, which I don’t want. How do I get my result without displaying HTML tags?

This is for displaying in html page

(and newsArray is type Object)
which is displaying data but with html tags

   <div *ngFor="let item of newsArray">
                    <div class="panel-body">
                      {{item.details}}
                    </div>   
   </div>

result given by this is:

<p>hello</p>

but expected result:

hello

2

Answers


  1. You can replace your result like this:

    getText() {
      return this.data.replace(/<[^>]*>/g, '');
    }
    

    This will replace all your html tags and keep only the blank text.

    See my stackblitz demo

    Login or Signup to reply.
  2. you can use [innerHtml] property on the div

    <div *ngFor="let item of newsArray">
                        <div class="panel-body" [innerHtml]='item.details'>
    
                        </div>   
       </div>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search