D
D
Drovosek012021-10-26 14:52:47
Angular
Drovosek01, 2021-10-26 14:52:47

What is the difference between markAsDirty and markAsTouched in Angular?

In Angular, in ReactiveForm, I set the value to one control from the form via .setValue(someValue)
As I understand it, in order to start the process of validating the set value after that, you need to execute the markAsDirty() and markAsTouched() methods of the same control? Or just one of them? What is the difference between them and when to use which one?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Shvets, 2021-10-27
@Drovosek01

In Angular, in ReactiveForm, I set a value to one control from the form through .setValue(someValue)

Inside any method that changes the form or its value, there is an updateValueAndValidity.
As I understand it, in order to start the validation process of the set value after that, you need to execute the markAsDirty () and markAsTouched () methods of the same control

No, these methods just change the flags, dirty and pristine, respectively. And they have nothing to do with the validation process.
What is the difference between them and when to use which one?

ny as intended, dirty is when the form changed, touched is when the control had focus and disappeared.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question