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

317
Vistas
How to include an Angular app dynamically into the DOM?

We created a widget as an Angular app, which our customers should be able to easily load and integrate into their own website.

The most straightforward way (which works) to do this is simply to tell them to include the default HTML tags from the index.html on their website:

<base href="/">
<app-root></app-root>
<script src="https://ourdomain.com/widget/runtime.js" type="module"></script><script src="https://ourdomain.com/widget/polyfills.js" type="module"></script><script src="https://ourdomain.com/widget/main.js" type="module"></script>

However, we would like to minimize the above code and provide them a one-liner which includes a JavaScript that loads the code dynamically into the DOM, e.g. <div id="widget"></div><script src="https://ourdomain.com/widget/start.js"></script>. The script would simply consist of:

<script>
document.getElementById('widget').innerHTML = '<base href="/"><app-root></app-root>...';
</script>

The tags are loaded correctly into the DOM but the Angular app i.e. the scripts which are dynamically included into the DOM don't load. How can this problem be solved? Is there a method in main.js which needs to be called additionally to bootstrap the Angular app?

The Angular app is deployed and hosted on our server, e.g. on https://ourdomain.com/widget. The goal is that anyone can load and plug the app into their own website using the above approach.

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

0

It turned out to work just like that:

<script>
    document.write('<base href="/"><app-root></app-root>...');
</script>
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