在我的应用程序中,我有两个模块。IdentityModule and ServiceModule
。它们是作为延迟加载技术加载的。
现在,我创建了一个IconSpacerDirective
与绑定的自定义指令app.module.ts
。我的电脑内部工作正常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 { }
我如何使用IconSpacerDirective
我的内部identityRegistryModule
如果要IconSpacerDirective
在AppModule
和中同时使用IdentityRegistryModule
,则需要为该指令创建一个单独的模块,然后可以将其导入所需的模块中。
@NgModule({
declarations: [IconSpacerDirective],
exports: [IconSpacerDirective]
})
export class IconSpacerModule { }
@NgModule({
imports: [IconSpacerModule]
})
export class AppModule { }
@NgModule({
imports: [IconSpacerModule]
})
export class IdentityRegistryModule { }
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句