Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
494 views
in Technique[技术] by (71.8m points)

javascript - 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
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...