<form class="form-horizontal" (submit)="submit($event)" [formGroup]="formUser">
<input name="firstname" formControlName="firstName">
<input name="lastname" formControlName="lastName">
<button type="submit" class="btn btn-default" >Submit</button>
</form>
有没有办法更新formUser的任何属性,比如“touch”或“value”,或者做些什么来验证submit(ev)函数中的所有输入?
答案 0 :(得分:0)
我认为如果使用 ngForm 输入任何内容,您可以输入所需输入并禁用按钮:
<form class="form-horizontal" (ngSubmit)="submit($event)" #myForm="ngForm">
<input name="firstname" ngControl="firstName" required>
<input name="lastname" ngControl="lastName" required>
<button type="submit" class="btn btn-default" [disabled]="!myForm.form.valid" >Submit</button>
</form>