您的位置:首页 > Web前端 > AngularJS

【angular】Type Component is part of the declarations of 2 modules

2017-11-30 15:36 387 查看
Uncaught Error: Type **Component is part of the declarations of 2 modules Please consider moving **Component to a higher module that imports **Module and **Module. You can also create a new NgModule that exports and includes **Component then import that NgModule in **Module and **Module.

问题分析

一个组件在两个模块中定义,导致报错。

解决方案

将该组件定义到模块中,在其他模块中引用该模块。

如以下,将InfoComponent定义到InfoModule模块中:

import {NgModule}      from '@angular/core';
import {BrowserModule} from '@angular/platform-browser';
import {InfoComponent} from "../info/info.component";

@NgModule({
imports: [BrowserModule
],
exports:      [ InfoComponent ],
declarations: [InfoComponent]
})
export class InfoModule {

}


再将该模块引用到其他模块的imports数组中。

angular、spring cloud 开源实战项目源码:https://gitee.com/xfdm/FCat

QQ群:549141844

代码持续更新…
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  angular