我有一个名为CustomerInfoModule的功能模块,该功能模块可导出CustomerInfoComponent。见下文。

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。我收到 typescript 错误




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文档,它说:



从模块中导入组件并在另一个模块中使用它是不合逻辑的。我是否认为/或缺少某种东西是错误的?

最佳答案

因为您是从模块文件导入的,所以可以执行以下操作。

客户信息模块

import {CustomerInfoComponent} from './customer-info.component';
export {CustomerInfoComponent};

关于Angular 2 : export component on a module and import and use it inside a module,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41960959/

10-09 22:33