angular父子组件之间的引入报错

报错: ERROR in : Type RecommendComponent in E:/2018/KYLIN-WEB/src/app/home/article-details/recommend/recommend.component.ts is part of the declarations of 2 modules: ArticleDetailsModule in E:/2018/KYLIN-WEB/src/app/home/article-details/article-details.module.ts and RecommendModule in E:/2018/KYLIN-WEB/src/app/home/article-details/recommend/recommend.module.ts! Please consider moving RecommendComponent in E:/2018/KYLIN-WEB/src/app/home/article-details/recommend/recommend.component.ts to a higher module that imports ArticleDetailsModule in E:/2018/KYLIN-WEB/src/app/home/article-details/article-details.module.ts and RecommendModule in E:/2018/KYLIN-WEB/src/app/home/article-details/recommend/recommend.module.ts. You can also create a new NgModule that exports and includes RecommendComponent in E:/2018/KYLIN-WEB/src/app/home/article-details/recommend/recommend.component.ts then import that NgModule in ArticleDetailsModule in E:/2018/KYLIN-WEB/src/app/home/article-details/article-details.module.ts and RecommendModule in E:/2018/KYLIN-WEB/src/app/home/article-details/recommend/recommend.module.ts.

这里写图片描述

article-details模块有四个子模块
刚开始的引用

article-details模块:
这里写图片描述

四个模块引入各自的component,用其中一个子模块recommend.module为例
这里写图片描述

于是打包时报错
这里写图片描述
翻译了一下
这里写图片描述
就是组件只能声明在一个模块里面

改进
把所有的组件声明在article-details模块里面,子模块不用再引入,每个子模块只需要引入article-details模块就可以了
这里写图片描述
这里写图片描述
这里是以其中一个子模块为例,其他三个也相同的操作
这样就可以通过编译了!

猜你喜欢

转载自blog.csdn.net/z15802933724/article/details/81983084