Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

396
Views
Cómo eliminar etiquetas html del texto en angular 2

Estoy trabajando con rss feed y obtuve rss feed de mi servidor, así que estoy enviando datos de stringfy, pero cuando vinculo esto en mi aplicación angular 2, muestra texto con etiquetas html, entonces, ¿cómo podemos eliminar estas etiquetas? Solo quiero mostrar solo texto.

Aquí está el código del servidor:

 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); });

servicio.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')); }

noticias.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>

obtuve respuesta con algunos como esto:

texto de ejemplo

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Solo necesita vincular html:

 <div *ngFor="let daily of tagesnews"> <span style="font-size: 13px" [innerHTML]="daily.text"></span> </div>
over 4 years ago · Santiago Trujillo Report

0

Hay dos formas de manejarlo.

1) use la etiqueta innerHTML en su archivo html como este =

 <div> <pre [innerHTML]="description"></pre> </div>

aquí, la descripción es un campo que contiene los datos con etiquetas html (<div>hi<br></br></div>)

2) La segunda forma es convertir sus datos de etiquetas html en una cadena simple y luego vincularlos con el control de formulario respectivo.

como :- formData['description'] = formData['description'].replace(/<[^>]*>/g, '');

over 4 years ago · Santiago Trujillo Report

0

Todas las respuestas [innerHTML] tienen el contenido del HTML realmente renderizado... así que las imágenes se cargan, etc. bueno, si no quieres eso, y solo el texto... puedes usar un método de conversión como este:

 stripHtml(html: string) { var div = document.createElement("DIV"); div.innerHTML = html; let cleanText = div.innerText; div = null; // prevent mem leaks return cleanText; }
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!