Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

179
Vistas
How to display paragraphs coming from a single element in Angular with the required characters working

I have a object in view.component.ts file coming form backend. It is supposed to be description for a product. It has more than 500 lines of text. for eg:

{"description" : "Hello my Name is Param Bedi.\r\nHow are you\r\n\r...continue till 500 lines and more"}

I need to display this to Angular view. But its just coming straight as it is ie containing all the "\r\n" etc. Its not inserting a new line instead of \n.

This is what I am doing in view.component.html

<div>
  <p>{{ data["description"] }}</p>
</div>

What should I do so that I can display the data with newline and other special characters working?

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You can use HTMLElement.innerText:

<div>
  <p [innerText]="data.description"></p>
</div>

Or, if you need special character output, using Element.innerHTML (with replacing new lines with <br>):

<div>
  <p [innerHTML]="data.description.replace(/(\r\n|\r|\n)/g, '<br>')"></p>
</div>
about 4 years ago · Juan Pablo Isaza Denunciar

0

Solution 1: You can use white-space: pre-line in css. You can check here CSS White Space.

Solution 2: You can use Textarea with readonly.

<textarea name="description" readonly [(ngModel)]="data.descrption" style="resize: none;" ></textarea>

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda