我正在使用Angular和延迟加载模块。每个组件都有自己的模块。如果我在根模块(app.module)中导入模块,它必须正常工作。例如,我在app.module中导入了HttpClientModule
,可以在子组件中使用它。
但关于FormsModule
,这不行。我必须在子模块中导入它,否则,我会收到以下错误:
Can't bind to 'ngModel' since it isn't a known property of 'input'. ("
Do you have any idea why this happens?
我找到了答案here:
创建SharedModule
@NgModule({
imports: [
CommonModule,
FormsModule,
],
declarations: [
],
exports: [
CommonModule,
FormsModule,
]
})
export class SharedModule {
}
并将其添加到app.module.ts
imports: [ SharedModule.forRoot(),
// Core Module
CoreModule.forRoot()]