Eran Shabi Eran Shabi - 1 month ago 16
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

You should use the markAsDirty method, like this:

control.markAsDirty();

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

Docs link

Comments