Eran Shabi Eran Shabi - 7 months ago 85
Javascript Question

How do I programmatically set an Angular 2 form control to dirty?

How do I mark an Angular 2 Control as dirty in my code?

When I do it like this:

control.dirty = true;

I get this error:

Cannot set property dirty of #<AbstractControl> which has only a getter


You should use the markAsDirty method, like this:


This will also mark all direct ancestors as dirty to maintain the model.

Docs link