当我尝试将表格与控件一起使用时,出现此错误。
Type 'AbstractControl' is missing the following properties from type
'FormControl': registerOnChange, registerOnDisabledChange, _applyFormState
表格代码
this.checkoutForm = this.fb.group({
firstName: ['', [Validators.required, Validators.pattern('[a-zA-Z][a-zA-Z ]+[a-zA-Z]$')]],
lastName: ['', [Validators.required, Validators.pattern('[a-zA-Z][a-zA-Z ]+[a-zA-Z]$')]],
phoneNumber: ['', [Validators.required, Validators.pattern('[0-9]+')]],
address: ['', [Validators.required, Validators.maxLength(100)]],
pinCode: ['', Validators.required]
});
html
<input type="text"
name="firstName"
[formControl]="checkoutForm.controls['firstName']"
value=""
placeholder=""
autocomplete="off"
>
答案 0 :(得分:4)
创建反应形式时,应该使用形式本身,而不是其控件。
如果仅单独使用控件,那么拥有表单的意义何在?
<form [formGroup]="checkoutForm">
<input type="text" formControlName="firstName">
</form>