Angular 8 setErrors set a control as invalid but doesn't update on template

Viewed 189

I have the following code on my component

   this.frmGroup.controls['dorms'].setErrors({'incorrect': true});

then in my template I have this to debug:

   {{this.frmGroup.controls['dorms'].invalid  }} 

After setting erros the invalid property of the dorms control is always false on the template

if I execute this:

this.frmGroup.controls['dorms'].setErrors({'incorrect': true}); console.log(this.frmGroup.controls['dorms'].invalid) // it is true but the template doesn't change it is as false

2 Answers

You may have to run this.frmGroup.get('dorms').updateValueAndValidity(); to get the changes recognized by your template.

Like iamword said or also this.frmGroup = ...this.frmGroup

Related