gpt4 book ai didi

angular - Angular 形式问题 : AbstractControl vs FormControl

转载 作者:行者123 更新时间:2023-12-04 12:06:03 29 4
gpt4 key购买 nike

当我尝试使用带有控件的表单时,出现此错误。

 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>

关于angular - Angular 形式问题 : AbstractControl vs FormControl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58213848/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com