【发布时间】:2020-04-08 23:59:57
【问题描述】:
在我的应用程序中,我有两个模块。 IdentityModule and ServiceModule。它们作为延迟加载技术加载。
现在我创建了一个与app.module.ts 绑定的自定义指令IconSpacerDirective。它在我的app.component.ts 中运行良好。
但它在 IdentityModule 中不起作用。我有这个错误:
ERROR Error: Uncaught (in promise): Error: Type IconSpacerDirective is part of the declarations of 2 modules: AppModule and IdentityRegistryModule! Please consider moving IconSpacerDirective to a higher module that imports AppModule and IdentityRegistryModule. You can also create a new NgModule that exports and includes IconSpacerDirective then import that NgModule in AppModule and IdentityRegistryModule.
Error: Type IconSpacerDirective is part of the declarations of 2 modules: AppModule and IdentityRegistryModule! Please consider moving IconSpacerDirective to a higher module that imports AppModule and IdentityRegistryModule. You can also create a new NgModule that exports and includes IconSpacerDirective then import that NgModule in AppModule and IdentityRegistryModule.
这是我的identityRegistryModule:
import { IconSpacerDirective } from '../shared/custom-directive/icon-spacer.directive';
@NgModule({
declarations: [
IconSpacerDirective
],
imports: [
IdentityRegistryRoutingModule,
MaterialModule
],
providers: [
IdentityService,
],
})
export class IdentityRegistryModule { }
我的app.module.ts如下:
import { IconSpacerDirective } from './shared/custom-directive/icon-spacer.directive';
@NgModule({
declarations: [
AppComponent,
MainNavComponent,
SideNavComponent,
HeaderComponent,
HomeComponent,
IconSpacerDirective,
],
imports: [
BrowserModule,
HttpClientModule,
AppRoutingModule,
FlexLayoutModule,
BrowserAnimationsModule,
LayoutModule,
MaterialModule,
OAuthModule.forRoot(),
],
providers: [],
bootstrap: [AppComponent],
//exports: [IconSpacerDirective]
})
export class AppModule { }
如何在我的identityRegistryModule 中使用IconSpacerDirective
【问题讨论】:
标签: angular typescript angular-directive angular-module