【发布时间】:2022-11-10 03:41:18
【问题描述】:
Angular Reactive form setValue将字符串设置为数字输入类型,输入框为空但在控件中分配了字符串值,所需的验证不起作用
这是表单控制器
ngOnInit() {
this.profileForm = new FormGroup({
name: new FormControl("", Validators.required),
age: new FormControl("", Validators.required),
}
}
patchAge(){
this.profileForm.controls["age"].setValue("somethingString");
}
这是模板
<form [formGroup]="profileForm" (ngSubmit)="onFormSubmit()">
<input
type="text"
formControlName="name"
/>
<input
type="number"
formControlName="age"
/>
</form>
【问题讨论】:
标签: angular angular-reactive-forms angular-formbuilder