首先,禁用按钮
<button type="submit" class="btn btn-primary" (click)="onSubmit()" [disabled]="!form.valid">Submit</button>
接下来,在提交之前使用条件。
onSubmit(){
if (!this.form.valid) return;
// console.log(this.form.controls.zip);
this.form.markAsTouched();
console.log(this.form.value);
}
最后,将该属性添加到您的表单中:
<form [formGroup]="form" novalidate>
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句