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

132
Vistas
id Attribute of innerHTML value disappears

I am trying to set the content of a DOM-Element with innerHTML, but it doesn't work as I expect it. The content which I want to set is an a Tag with id and href as attributes, however the id attribute isn't there on the rendered content.

Example Code:

import { Component } from '@angular/core';
@Component({
    selector: 'app-root',
    template: `<div [innerHTML]="html"></div>`,
    styleUrls: ['./app.component.css']
})
export class AppComponent {
    title = 'Angular';
    html = '<a href="/" id="foo">link</a>';
}

Any help is welcome.

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

0

You should use bypassSecurityTrustHtml method to tell angular that this html is safe to use.

      html = this.sanitizer.bypassSecurityTrustHtml('<a href="/" id="foo">link</a>');
      constructor(private sanitizer: DomSanitizer){}

Working Stackblitz

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