0

I'm working with a Reactive form and I have noticed in some tutorials they do the following:

HTML

.
.
<input type="text" formControlName="firstName" required>
.
.

TS

.
.
firstName: ['', Validators.required]
.
.

QUESTION:

Why do I need to specify "required" in the HTML if I just do it in the TS file it works fine?

0

1 Answer 1

3

Actually, Angular mention something about that here:

Caution: Use these HTML5 validation attributes in combination with the built-in validators provided by Angular's reactive forms. Using these in combination prevents errors when the expression is changed after the template has been checked.

Sign up to request clarification or add additional context in comments.

2 Comments

Can you please elaborate this comment as it does not completely explains exactly what happens to validation after ExpressionChangedAfterItHasBeenCheckedError is thrown by Angular when the expression is changed after the template has been checked. I have encountered no error in validation after ExpressionChangedAfterItHasBeenCheckedError is thrown irrespective of whether I use HTML5 validation or not. However, I get another error object printed in console which I don't understand. Thanks.
Is there a way to extract these from the TS validators that are created?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.