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

291
Vistas
How can I render HTML from a string? using angular

I have a database variable from which I get this, for example:

hello, `<br />` have a good day,

It prints the <br /> to my screen. How could I tell html that
is a line break?

My variable is called greeting and it is an array from which I use a for to print everything, but I used that little text as an example.

So I tried with innerHTML but it doesn't work:

  <i id="break" class="textTitle">{{ greeting }}</i>
      <script>
         document.getElementById("break").innerHTML = "<br/>";
      </script>

UPDATE

my solution was:

<div [innerHTML]="greeting" ></div>
about 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

Use the dangerouslySetInnerHTML prop:

<i id="break" class="textTitle" dangerouslySetInnerHTML={greeting}></i>

Your original code uses innerText under the hood to set the content of the element. That's why it gets interpreted as text instead of HTML code.

<i id="break" class="textTitle">{{ greeting }}</i>
about 4 years ago · Santiago Trujillo Denunciar

0

In must be something to do with the way you interpreter is treating the text, as this should normally work fine:

document.getElementById("break").innerHTML = "<br/>";
<body>
 <h1>Hi</h1>
 <h1 id="break"></h1>
 <h1>There</h1>
</body>

about 4 years ago · Santiago Trujillo 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