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

357
Vistas
How can I do text interpolation in HTML and JS like I do in Angular? (If possible)

I want to do a text interpolation in HTML and JS like i usually do in angular, I know that it doesn't work if I do the exact same way:

var myPhrase = 'This is my phrase>!';
<body>
  <p> {{myPhrase}} </p>
</body>
Since the angular way is "easier", I'm trying to avoid the text insertion by the myTag.innerHTML = 'something here' So my question is: If possible how can I do it?

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

0

Unfortunately, I don't believe you can do this in vanilla JS. Perhaps you could do something like this:

let greeting = 'Hello World!';
let message = 'How is the weather today?';

let str2 =
    `<h1>${greeting}</h1>
    <p>${message}</p>`;

console.log(str2);

But this does not have the same ease of use. You will probably have to use myTag.innerHTML = 'something here' as you said.

about 4 years ago · Juan Pablo Isaza Denunciar

0

It can be done but it's cumbersome and not pretty. You simpley embed script tags in the html and document.write output as needed.

This is one of the few examples where document.write can be used successively as each use is occurring while the page is being interpretted.

<body>
  <p> <script>document.write("hello")</script> world, <script>let phrase="how are you today?"; document.write(phrase);</script></p>
</body>

in the context of filling in stored data, each variable can be defined in an earlier script (so will be available to the future insering tags. Like this:

<script>
let myName = "David";
let myAge = "99";
let myBirthday = "tomorrow";
</script>

<h2>Hello, my name is <script>document.write(myName);</script></h2>

<p>It's my birthday <script>document.write(myBirthday);</script></p>

<p><script>document.write(`I will be ${myAge} years old`);</script></p>

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