typescript - Angular Formları ile İlgili Sorun: AbstractControl ve FormControl


Bir formu kontrollerle kullanmaya çalıştığımda bu hatayı alıyorum.

 Type 'AbstractControl' is missing the following properties from type 
'FormControl': registerOnChange, registerOnDisabledChange, _applyFormState

Form Kodu

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

Cevap #1

Reaktif formlar oluşturduğunuzda, formun kendisini kullanmanız, kontrollerini değil, gerekir.

Eğer kontrolleri ayrı ayrı kullanıyorsanız, o zaman bir forma sahip olmanın amacı ne?

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

Cevap #2

Bu benim için işe yarıyor. yani $any()

  <ion-checkbox
      
        [formControl]="$any(fc)"
      
        (ionChange)="changeCheckbox()"
      >

İlgili makaleler