>角度
我想做什么
我做了什么
>我创建了一个名为’loading-overlay’的新模块
>在此模块中,我导出叠加组件
>我将此模块添加到app.module
>将组件添加到多个模块时,我收到以下错误:
Type LoadingOverlayComponent is part of the declarations of 2 modules: LoadingOverlayModule and ProjectsModule! Please consider moving LoadingOverlayComponent to a higher module that imports LoadingOverlayModule and ProjectsModule. You can also create a new NgModule that exports and includes LoadingOverlayComponent then import that NgModule in LoadingOverlayModule and ProjectsModule.
>我已经尝试将其从app.module中删除并将其导入我需要的其他模块而没有太多运气.我必须遗漏一些明显的东西.
叠加模块
// Modules import { NgModule } from '@angular/core'; // Components import { LoadingOverlayComponent } from './loading-overlay.component'; @NgModule({ declarations: [ LoadingOverlayComponent,],imports: [ ],exports: [ LoadingOverlayComponent ],providers: [ ],}) export class LoadingOverlayModule { }
应用模块
import { browserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; import { AppComponent } from './app.component'; // Routing import { AppRouting } from './routing/app-routing'; // Modules import { ProjectsModule } from './projects/projects.module'; import { UserModule } from './user/user.module'; import { LoadingOverlayModule } from './loading-overlay/loading-overlay.module'; // Services / Providers import { AuthService } from './user/auth.service' @NgModule({ declarations: [ AppComponent,imports: [ browserModule,AppRouting,LoadingOverlayModule ],providers: [ AuthService,bootstrap: [AppComponent] }) export class AppModule { }
项目模块
// Modules import { NgModule } from '@angular/core'; import { CommonModule } from '@angular/common'; import { RouterModule } from '@angular/router'; import { LoadingOverlayModule } from '../loading-overlay/loading-overlay.module'; import { LoadingOverlayComponent } from '../loading-overlay/loading-overlay.component'; @NgModule({ declarations: [ LoadingOverlayComponent ],imports: [ CommonModule,RouterModule,LoadingOverlayModule ],}) export class ProjectsModule { }
任何帮助指出我愚蠢错过的将非常感谢:)
解决方法
来自AppModule的LoadingOverlayModule
来自ProjectsModule的LoadingOverlayComponent
而且:
import LoadingOverlayModule其所需的位置
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。