Angular Reactive form validation

我是研究僧i 提交于 2021-01-29 14:16:08

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/53583529/angular-reactive-form-validation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!