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.
customer-info.module.ts
customer-info.module.ts
import {CustomerInfoComponent} from './customer-info.component';
export {CustomerInfoComponent};
这篇关于Angular 2:在模块上导出组件,然后在模块内部导入和使用它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!