text color of all required input field change to invalid color when adding a dynamic formControl

戏子无情 提交于 2019-12-01 14:32:18

All of the formcontrols inside named as '[formControl]="innerControl"' so if one goes error all goes error. change the value something dinamic

Buttons inside forms are by default of type submit. So what actually happens on add button click, is that the form is submitted, and angular material has the behavior that if a form is submitted, all required fields shows error. So that is what is going on currently. If you have a button inside form that shouldn't behave like submit, you need to explicitly say that it should be of type button. So add type="button" to those buttons:

<button (click)="addElem(control.key)" type="button">+</button>
<button (click)="removeElem(control.key, i)" type="button">-</button>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!