Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable button in angular with two conditions?

Is this possible in angular ?

<button type="submit" [disabled]="!validate && !SAForm.valid">Add</button> 

I expect that if both of the conditions are true they will enable the button.

I've already tried the above code but it's not working as expected.

like image 351
MariaJen Avatar asked Apr 21 '17 05:04

MariaJen


People also ask

How do I disable a button in Angular?

To disable button in Angular, we set the [disabled] attribute. to set the [disabled] attribute to 'disabled' if editmode is false . Otherwise, we set it to null to keep the button enabled.

How do you disable a button until another button is clicked in Angular?

Component tsactionMethod($event: MouseEvent) { ($event. target as HTMLButtonElement). disabled = true; // Do actions. }

How do you write if condition in NG-disabled?

Or you can use ng-disabled="condition1 || condition2" , is depend of you logic conditional.


1 Answers

It sounds like you need an OR instead:

<button type="submit" [disabled]="!validate || !SAForm.valid">Add</button> 

This will disable the button if not validate or if not SAForm.valid.

like image 158
DeborahK Avatar answered Sep 23 '22 05:09

DeborahK