Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

174
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!