Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Angular disable button if variables are empty

<button
    [disabled]="doSummary=== '' && selectedLOB === '' && adsList === ''"
    class="lmn-btn lmn-btn-primary"
    aria-label="Update"
    (click)="updateSelectedScopes()"
  >
  Update
</button>

I’ve an usecase where I need to disable the button if all 3 variables are EMPTY '' and if any of the variable is not empty, button shouldn’t be disabled. Currently I tried this way also variables are empty but its not disabling the button, not sure what’s the issue

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

This should work, assuming you initialized your variables to empty string.

So create your variables like this

doSummary: string = '';

Instead of

doSummary: string;

Or you can check for something like this

<button
    [disabled]="(!doSummary || doSummary === '') && (!selectedLOB || selectedLOB === '') && (!adsList || adsList === '')"
    class="lmn-btn lmn-btn-primary"
    aria-label="Update"
    (click)="updateSelectedScopes()"
  >
  Update
</button>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading