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

222
Views
How to simplify a button using a boolean?

I have these 2 inputs (buttons)

 <div class="modal-footer">
    <button class="btn btn-secondary" (click)="close()">Close</button>
    <input *ngIf="!isEdit" type="button" class="btn btn-primary" (click)="addCustomer(myForm)" value='Add data'>
    <input *ngIf="isEdit" type="button" class="btn btn-success"  (click)="updateCustomer(myForm)" value='Update'>
 </div>

where if isEdit is false then I want to show the button "Add data" else I want to show the button "Update" but I wonder if there's a way to simplify this a bit more rather than using 2 inputs for each. Thanks in advance!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

else capability was added somewhat recently; that's probably why most documentation doesn't have it (yet). But you can write this way:

<div class="modal-footer">
  <button class="btn btn-secondary" (click)="close()">Close</button>
  <input *ngIf="!isEdit; else update" type="button" class="btn btn-primary" (click)="addCustomer(myForm)" value='Add data'>
</div>
<ng-template #update>
   <input type="button" class="btn btn-success"  (click)="updateCustomer(myForm)" value='Update'>
</ng-template>

It works; but I don't know how much better it is compared to what you have.

about 4 years ago · Juan Pablo Isaza 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!