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

281
Vistas
How to call the function with variable in innerHtml?

I've found example of calling function in innerHtml https://stackblitz.com/edit/angular-innerhtml-examples , but I don't know what to do, if function needs variable, which acceptable only from controller:

 constructor(private elementRef: ElementRef, private sanitizer: DomSanitizer) {
    const currentString = "green";
    this.content = this.sanitizer.bypassSecurityTrustHtml(
      '<button type="button" id="submitButton" (click)="openWindow()">Submit</buttn>'
    );
  }
  openWindow(string) {
    alert(string);
  }
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Try to add your variable as a param to addEventListener('click',someEventHander.bind(this, param1)).

Check this stackblitz example: https://stackblitz.com/edit/angular-innerhtml-examples-hdw7xs?file=src%2Fapp%2Fapp.component.ts

You can also refer to: https://www.codegrepper.com/code-examples/javascript/addeventlistener+with+arguments+in+angular+8

Also it is better/clean way to use bypassSecurityTrustHtml into angular pipe then call it from [innerHtml]. I adapted the above stackblitz example to use this way.

And finally, please use console.log() instead of alert() when debugging an application. for reason and more details: Why is console.log() considered better than alert()?

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