How to disable / enable ion 2 button?

I have an input field and a button. It must be disabled at startup. When the input is empty, the button is turned on.

I use ngModel to input an input value and a function (change) to run a function every time the input changes.

Now I do a little if the function changes.

if(input !== ''){ //enable the button }else{ //disable the button } 

Do you know how to achieve this?

thanks

+6
source share
1 answer

Just enter a boolean into the class:

 isenabled:boolean=false; 

Change function

 if(input !== ''){ //enable the button isenabled=true; }else{ //disable the button isenabled=false; } 

In html:

 <button ion-button [disabled]="!isenabled"></button> 

To change classes:

 <button ion-button [ngClass]="{class:isenabled,class2:!isenabled}"></button> 

Check here

+31
source

Source: https://habr.com/ru/post/1014682/


All Articles