我已将共享模块添加到我的应用程序中。看起来很简单。
const imports = [
CommonModule,
RouterModule,
BrowserModule,
FormsModule, ReactiveFormsModule
];
@NgModule({imports})
export class SharedModule {}
当我将共享模块导入另一个模块时,它看不到我导入的人员。我收到这样的错误“无法绑定(bind)到‘formGroup’,因为它不是‘form’的已知属性。(”,这意味着 FormsModule 未正确导入。 如果我将基本模块直接导入到我的应用程序模块中,它就可以正常工作。
非常感谢您的帮助和建议。
最佳答案
您很可能还需要导出这些模块。
通常:
@NgModule({
imports: [
SomeModule
],
declarations: [
...
],
exports: [
SomeModule,
]
});
另请参阅此 angular多可...
By re-exporting CommonModule and FormsModule, any other module that imports this SharedModule, gets access to directives like NgIf and NgFor from CommonModule and can bind to component properties with [(ngModel)], a directive in the FormsModule.
关于Angular 共享模块导入不导入提到的模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54417156/