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

181
Vistas
How to render dynamic components in Angular 13 or higher

I'm working on an Angular 13 project, and I need to render dynamic components. The component template and the biz logic come from the server-side as a string. I read that you can't create templates dynamically in Angular 13, as any component must be compiled by Angular at build time, and Angular apps do not ship with the JIT compiler.

This is only for one part of the application where I allow customers to build their custom dashboards.

It was possible to do that in Angular 12, but in Angular 13 the compiler service is no longer exposed.

Code working in Angular 12:

Template:

<div>
   <ng-container *ngComponentOutlet="component"></ng-container>
</div>

Component:

import { Compiler, Component, NgModule, OnInit } from '@angular/core'
    @Component({
       selector: 'my-lab',
       templateUrl: './lab.component.html',
       styleUrls: ['./lab.component.scss'],
    })
        export class LabComponent implements OnInit {
           component: any
           constructor(private compiler: Compiler) {}
        
           async ngOnInit() {
              const componentClass = class {
                 public testing = {
                    name: 'yago',
                 }
              }
              const imports = (this.component = await this.compile({
                 template: `<div>Testing here {{ testing | json}}</div>`,
                 componentClass,
                 imports: [CommonsModule],
              }))
           }
        
           async compile(input: any) {
              const { template, componentClass, imports } = input
              const templateCompoment = Component({ template })(componentClass)
        
              const module = NgModule({
                 declarations: [templateCompoment],
                 exports: [templateCompoment],
                 imports: [...imports],
              })(class {})
        
              const compiledModule = await this.compiler.compileModuleAndAllComponentsAsync(module)
              return templateCompoment
           }
        } 

I wonder if you need to use a different set of APIs in Angular 13 or higher to be able to do this. Has anyone done this?

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

0

Maybe this could help you if I understand correctly what you want to do https://material.angular.io/cdk/portal/overview

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