这是我尝试编译时得到的错误(ng build --prod):
Error at /angular/src/app/.../xxx.component.html(xx,xxx): Argument of type 'AbstractControl' is not assignable to parameter of type 'FormControl'.
Property 'registerOnChange' is missing in type 'AbstractControl'.
有问题的代码(假设):
this.myForm = new FormGroup({
oneField: new FormControl('', [Validators.required,customValidator()])
});
并且:
ngChangeOnefield(event: FormControl){
// some code...
}
在我的html组件中,我有类似的东西:
<form [formGroup]="myForm" (ngSubmit)="onFormSubmit()">
<!-- more code -->
<htmltag (onSelect)="ngChangeOneField(oneField)"/>
<!-- more code -->
</form>
我通过更改代码解决了这个问题:
ngChangeOnefield(event: FormControl){
// some code...
}
至
ngChangeOnefield(event: AbstractControl){
// some code...
}
因此,对于事件触发,事件的良好类型是AbstractControl而不是FormControl