问题

当我尝试使用带有控件的表单时,我收到此错误.

  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"      
>
 

  最佳答案

当您创建反应形式时,您应该使用表单本身,而不是它的控件。

如果你单独使用控件,那么表单的重点是什么?

 <form [formGroup]="checkoutForm">
  <input type="text" formControlName="firstName">
</form>
 

  相同标签的其他问题

angularangular-forms