Help needed with setting a class dynamically. Any guidance is appreciated.
Below is the class in my SCSS file:
.form-validation.invalid {
border: 2px solid red
}
In my ts file, there's a variable named isEmailValid
. When this variable is set to false
, I want the border to appear; otherwise not. Here's my code:
HTML:
<input type="email" class="form-validation" [ngClass]="{'invalid': isEmailValid}"
TS:
//make service call and decide whether email is valid or not
if(value){ //value is the service response
this.isEmailValid = true;
} else {
this.isEmailValid = false;
}
After implementing the above code, the class is not being applied. What could be the issue? Please provide some advice.