問題

當我嘗試使用帶有控制元件的表單時,我收到此錯誤.

  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