I'm using Angular with lazy loading modules. Each component has its own module. If I import a module in the root module (app.module) it must work fine. For example, I imported HttpClientModule
in app.module and can use it in child components.
But about FormsModule
, this doesn't work fine. I must import it in the child module, otherwise, I get the following errors:
Can't bind to 'ngModel' since it isn't a known property of 'input'. ("
Do you have any idea why this happens?
I found the answer here :
create the SharedModule
@NgModule({
imports: [
CommonModule,
FormsModule,
],
declarations: [
],
exports: [
CommonModule,
FormsModule,
]
})
export class SharedModule {
}
and add this to app.module.ts
imports: [ SharedModule.forRoot(),
// Core Module
CoreModule.forRoot()]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.