I have a form created with formbuilder in my SettingsComponent:
constructor(){
this.userForm = this.formBuilder.group({
'firstname': ['', Validators.required],
'lastname': ['', Validators.required],
'email': ['', Validators.compose([Validators.required, ValidationService.emailValidator])]
});
}
what I want to do now is add a class to my input when the value is not valid. But when I do this:
<label class="input" [ngClass]="{'state-error': lastname.valid}">
<input ngControl="lastname" [(ngModel)]="user.lastname" id="lastname" #lastname="ngForm"/>
</label>
<small [hidden]="lastname.valid" class="form-required-field-info">this is a required field</small>
this produces the following error:
Expression '{'state-error': lastname.valid} in SettingsComponent@60:57' has changed after it was checked. Previous value: 'null'. Current value: 'false'
Link to demo: https://plnkr.co/edit/WvycldydiuMsi8HwgIYc
What am I missing? Any hints? Thanks in advance!