gpt4 book ai didi

angular - 错误错误 : No value accessor for form control with unspecified name attribute on switch

转载 作者:太空狗 更新时间:2023-10-29 16:49:51 25 4
gpt4 key购买 nike

这是我的 Angular 组件:

@Component( {
selector: 'input-extra-field',
template: `
<div class="form-group" [formGroup]="formGroup" >
<switch [attr.title]="field.etiquette"
[attr.value]="field.valeur" [(ngModel)]="field.valeur"
[formControl]="fieldControl" [attr.id]="name" [attr.disabled]="disabled">
</switch>
<error-messages [control]="name"></error-messages>
</div>
`
} )

这是我的类(class):

export class SwitchExtraField extends ExtraField {
@Input() field: ExtraFormField;
@Input() entity: { fields: Object };
@Input() formGroup: FormGroup;

constructor( formDir: NgForm ) {
super( null, null, formDir );
}

get disabled(): string {
if ( this.field && !!this.field.saisissable && !this.field.saisissable ) {
return 'disabled';
}
return null;
}
}

这是我在编译时遇到的错误:

ERROR Error: No value accessor for form control with unspecified name attribute
at _throwError (forms.es5.js:1918)
at setUpControl (forms.es5.js:1828)
at FormControlDirective.webpackJsonp.../../../forms/@angular/forms.es5.js.FormControlDirective.ngOnChanges (forms.es5.js:4617)

当我将元素开关更改为输入时,它可以正常工作,因为我知道我对其他组件使用相同的结构并且它工​​作正常。

最佳答案

我通过将 name="fieldName"ngDefaultControl 属性添加到带有 [(ngModel)] 属性的元素来修复此错误。

关于angular - 错误错误 : No value accessor for form control with unspecified name attribute on switch,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46422007/

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