[英]Angular Shared Module import does not import mentioned modules
I have added shared module to my app. 我已将共享模块添加到我的应用程序。 It looks pretty simple.
看起来很简单。
const imports = [
CommonModule,
RouterModule,
BrowserModule,
FormsModule, ReactiveFormsModule
];
@NgModule({imports})
export class SharedModule {}
When I import my shared module into another module it does not see my imported staff. 当我将共享模块导入另一个模块时,看不到导入的人员。 I get error like this "Can't bind to 'formGroup' since it isn't a known property of 'form'. (" ,which means that FormsModule is not imported correctly. If I import that basic modules directly into my app module it works OK.
我收到这样的错误:“无法绑定到'formGroup',因为它不是'form'的已知属性。(”,这意味着FormsModule无法正确导入。如果我将基本模块直接导入到我的应用模块中它工作正常。
Your help and advises are highly appreciated. 非常感谢您的帮助和建议。
Most likely you will need to also export those modules. 您很可能还需要导出这些模块。
Typically: 典型:
@NgModule({
imports: [
SomeModule
],
declarations: [
...
],
exports: [
SomeModule,
]
});
Also see this angular doco... 另请参阅此角形文档...
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.
通过重新导出 CommonModule和FormsModule,导入此SharedModule的任何其他模块都可以从CommonModule访问NgIf和NgFor之类的指令,并且可以使用FormsModule中的指令[[ngModel)]绑定到组件属性。
You have to export the dependency modules which used inside the shared module in order to use the shared module from some where else which does not import those dependencies. 您必须导出在共享模块中使用的依赖模块,以便从其他不导入这些依赖关系的地方使用共享模块。
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { CustomerComponent } from './customer.component';
@NgModule({
imports: [ CommonModule ],
declarations: [ CustomerComponent ],
exports: [ CustomerComponent
CommonModule, FormsModule ]
})
export class SharedModule { }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.