Friday, February 23, 2024
 Popular · Latest · Hot · Upcoming
193
rated 0 times [  200] [ 7]  / answers: 1 / hits: 52055  / 7 Years ago, fri, february 3, 2017, 12:00:00

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


More From » angular

 Answers
37

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


[#59084] Wednesday, February 1, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
luizc

Total Points: 623
Total Questions: 87
Total Answers: 103

Location: Zimbabwe
Member since Sat, Feb 27, 2021
3 Years ago
;