How disable/enable button with ionic 2?

51,151

Just have a boolean variable in 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>

For changing classes:

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

Check here

Share:
51,151
anubis
Author by

anubis

Updated on July 05, 2022

Comments

  • anubis
    anubis almost 2 years

    I have an input field and a button. It must be disable at start. When the input no blank is, the button is enable.

    I use a ngModel to take the value of the input and a function (change) to start a function each time the input is changed.

    Now I do a little if in the change function.

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

    Have you any idea how to achieve that?

    Thanks