Angular 2:在模块上导出组件并在模块内导入和使用它 [英] Angular 2 : export component on a module and import and use it inside a module
问题描述
我有一个名为 CustomerInfoModule 的功能模块,它导出一个 CustomerInfoComponent.见下文.
I have a feature module called CustomerInfoModule which exports a CustomerInfoComponent. see below.
import {NgModule} from '@angular/core'
import {RouterModule} from '@angular/router'
import {CustomerInfoComponent} from './customer-info.component'
@NgModule({
declarations:[CustomerInfoComponent],
exports:[CustomerInfoComponent]
})
export class CustomerInfoModule{
}
我想在 MissedCollectionsComponent 中导入和使用这个 CustomerInfoComponent.我收到打字稿错误
I want to import and use this CustomerInfoComponent inside MissedCollectionsComponent. I am getting typescript error
'.module"' 没有导出的成员 'CustomerInfoComponent'
'.module"' has no exported member 'CustomerInfoComponent'
.
import {NgModule} from '@angular/core'
import {RouterModule} from '@angular/router'
import {MissedCollectionsComponent} from './missed-collections.component'
import {CustomerInfoComponent} from '../shared/customer/customer-info.module'
@NgModule({
imports:[RouterModule.forChild([
{path:'missedcollection',component:MissedCollectionsComponent},
{path:'missedcollection/customerinfo',component:CustomerInfoComponent}
]),
CustomerInfoModule],
declarations:[],
exports:[]
})
export class MissedCollectionsModule{
}
根据 Angular2 文档,它说:
As per the Angular2 documentation it says:
'我们导出 ContactComponent 以便其他模块导入ContactModule 可以将它包含在他们的组件模板中.链接
'We export the ContactComponent so other modules that import the ContactModule can include it in their component templates.' link
从一个模块导入组件并在另一个模块中使用它是否不合逻辑.我是不是想错了/或错过了什么?
Is it not logical to import componets from a module and use it inside another module. Am I wrong thinking that/or missing someting?
推荐答案
因为你是从模块文件中导入的,所以你可以这样做.
because you import from module file, you could do something like this.
客户信息.module.ts
customer-info.module.ts
import {CustomerInfoComponent} from './customer-info.component';
export {CustomerInfoComponent};
这篇关于Angular 2:在模块上导出组件并在模块内导入和使用它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!