Angular 2 : export component on a module and import and use it inside a module

有些话、适合烂在心里 提交于 2019-12-06 19:48:00

问题


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{
}

I want to import and use this CustomerInfoComponent inside MissedCollectionsComponent. I am getting typescript error

'.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{

}

As per the Angular2 documentation it says:

'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?


回答1:


because you import from module file, you could do something like this.

customer-info.module.ts

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


来源:https://stackoverflow.com/questions/41960959/angular-2-export-component-on-a-module-and-import-and-use-it-inside-a-module

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!