出现此错误信息的原因是没有导入FormsModule或ReactiveFormsModule模块。解决方法是在需要使用表单的组件中,导入相应的模块。
例如,在使用FormGroup时,需要在组件的模块中导入ReactiveFormsModule模块:
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { ReactiveFormsModule } from '@angular/forms';
@NgModule({
declarations: [YourComponent],
imports: [CommonModule, ReactiveFormsModule],
})
export class YourModule { }
导入后,需要在组件的模板中使用formGroup来建立表单:
上一篇:Angular11中出现'Xh.Subjectisnotaconstructor”错误。
下一篇:Angular11中出现了TypeError:control.registerOnChangeisnotafunction错误。