此错误通常发生在表单中使用ngModel时,出现了不受支持的控件类型。解决方法是在控件中使用FormControl或FormGroup来代替ngModel,例如:
在组件中定义FormControl:
import { Component } from '@angular/core'; import { FormControl } from '@angular/forms';
@Component({
selector: 'app-my-component',
template:
})
export class MyComponent {
myControl = new FormControl();
}
在组件中定义FormGroup:
import { Component } from '@angular/core'; import { FormGroup, FormControl } from '@angular/forms';
@Component({
selector: 'app-my-component',
template:
})
export class MyComponent {
myForm = new FormGroup({
myControl: new FormControl()
});
}
使用FormControl或FormGroup可以有效解决该错误。
上一篇:Angular11中出现了错误信息'Can'tbindto'formGroup'sinceitisn'taknownpropertyof'form'”。
下一篇:Angular11中出现“No'Access-Control-Allow-Origin'headerispresentontherequestedresource”错误