I have this reactive form input that I want to add a green or red bottom-border to depending on its validation. In the below example I only have the validation required and when an input is touched and is invalid I want to add the class .invalid-input { bottom-border: 3px solid red}. I tried the below code, but it isn't working. When I leave the input blank and move away to another input it doesn't show any border. Can someone see why?
<input
id="firstName"
class="form__input"
type="text"
placeholder="First Name"
(keyup.enter)="getErrors()"
formControlName="firstName"
ngClass="{
'invalid-input': firstName.invalid && (firstName.dirty || firstName.touched)
}"
>
CSS
.valid-input {
border-bottom: 3px solid green;
}
.invalid-input {
border-bottom: 3px solid red;
}