How to remove html tags from text in angular 2

I am working with rss feed and receiving rss feed from my server, so I am posting string data, but when I link this in my angular 2 app it shows the text with html tags so we can remove those tags. I just want to show only the text.

Here is the server code:

exports.newspage=function(req,resp){
db.executeSql("select header,text,teaser from news_d",function(data,err){
        if(err){
            resp.writeHead(200,{"Content-Type":"text/html"});
            resp.write("<html><head><title>500</title></head></html>");
        }
        else{
            resp.writeHead(200,{"Content-Type":"x-application/json"});
            resp.write(JSON.stringify(data));
        }
        resp.end();
    });
};

app.get('/newspage', function(req, resp) {

    emp.newspage(req,resp);

});

      

service.ts:

gettagesnews(){
     let headers = new Headers();
       headers.append('x-access-token',this.token);
         var options = new RequestOptions({headers: headers});
      return this.http.get('http://services.com:9000/newspage/',options).map((res:Response) => res.json())
    .catch((error:any) => Observable.throw(error.json().error || 'Server error'));
  }

      

news.ts:

tagesnews:Array<TagesnewsList>;

this.newsauth.gettagesnews().subscribe((dailynews)=>{
    this.tagesnews=dailynews;
  });

      

HTML:

<div *ngFor="let daily of tagesnews">
       <span style="font-size: 13px">{{daily.text}}</span> </button>
    </div>

      

I got an answer with some in the following way:

sample text

+3


source to share


1 answer


You just need to link the html:



<div *ngFor="let daily of tagesnews">
   <span style="font-size: 13px" [innerHTML]="daily.text"></span>
</div>

      

+8


source







All Articles