gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 17:01:37 24 4
gpt4 key购买 nike

我有一个名为 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 错误

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

'We export the ContactComponent so other modules that import the ContactModule can include it in their component templates.' link

从一个模块中导入组件并在另一个模块中使用它是不合逻辑的吗?我是不是想错了/或错过了什么?

最佳答案

因为您是从模块文件导入的,所以您可以这样做。

客户信息.module.ts

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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com