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

163
Vistas
Angular dynamic templates with innerHTML convert the method to string

I try to load html with innerHTML but it does not work.

page.ts

htmlStr = `<div [ngClass]="getClass('COLECTOR')">HELLO WORLD</div>`;

page.html

<div [class]="getClass('COLECTOR')"> </div>

When I inspect code in Chrome:

-If i use [innerHtml] the method doesn't work. See the method as string:

<div [ngclass]="getClass('COLECTOR')">HELLO WORLD</div>

-If I don't use the pipe i only see:

<div>HELLO WORLD</div>

But.............

If i put the div tag in the page.thml without load the html from the string with innerHTML it works

<div [ngClass]="getClass('COLECTOR')">HELLO WORLD</div>

when inspect the code i see:

<div class="manual">HELLO WORLD</div>

This last is what i want to get but loading the HTML from a string.

pipe

@Pipe({
  name: "domSanitizer",
})
export class DomSanitizerPipe implements PipeTransform {
  constructor(private sanitizer: DomSanitizer) {}

  transform(value: string, type: string): SafeHtml | SafeStyle | SafeScript | SafeUrl | SafeResourceUrl {
        switch (type) {
            case 'html':
                return this.sanitizer.bypassSecurityTrustHtml(value);
...
about 4 years ago · Santiago Gelvez
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