Eran Shabi Eran Shabi - 1 year ago 288
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

Answer Source

You should use the markAsDirty method, like this:


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

Docs link

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download