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

176
Vistas
Using this in Angular template with reference

In ourcomponent HTML we have a modal with a reference name. Inside this modal we have buttons to close the modal.

Here is the code:

<div bsModal #confirmModal="bs-modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="confirm modal" aria-hidden="true">
  <div class="modal-dialog modal-md">
    <div class="modal-content">
      <div class="modal-header">
        <h4 class="modal-title pull-left">Confirm</h4>
        <button type="button" class="close pull-right" aria-label="Close" (click)="confirmModal.hide()">
        <span aria-hidden="true">&times;</span>
      </button>
      </div>
      <div class="modal-body">
        <span>Are you sure ?</span>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" (click)="confirmModal.hide()">Cancel</button>
        <button type="button" class="btn btn-danger" (click)="confirmModal.hide()">Refresh Data</button>
      </div>
    </div>
  </div>
</div>

To close it, we currently call for example (click)="confirmModal.hide()". Using the reference name.

Since we are inside the div with reference #confirmModal, is it possible to maybe have a way to call the hide function using (click)="this.hide()"

Of course I tried this syntax and it doesn't work as expected as this refers to component as I understand.

As a bonus: do you have any idea where I can find information on Angular doc about this reference syntax #reference to name a part of my html? I use it without exactly knowing all its possibilities.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

The #abc is called a template reference variable. You can find out more about it here: https://angular.io/guide/template-syntax#ref-vars

over 4 years ago · Santiago Trujillo 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