我创建了一个共享模块,并声明了&在其他模块中导出了我需要的组件.
i have created a shared module and declared & exported the component i need in other modules.
import { NgModule } from '@angular/core'; import { CommonModule } from '@angular/common'; import { DateslideComponent } from './dateslide/dateslideponent'; import { IonicModule } from '@ionic/angular'; import { TimeslideComponent } from './timeslide/timeslideponent'; import { AddtimeComponent } from './addtime/addtimeponent' @NgModule({ declarations: [DateslideComponent, TimeslideComponent, AddtimeComponent], imports: [ CommonModule, IonicModule ], exports: [DateslideComponent, TimeslideComponent, AddtimeComponent] }) export class TimeModule { }在另一个模块中,我已导入共享模块.
in another module i have imported the shared module.
import { NgModule } from '@angular/core'; import { CommonModule } from '@angular/common'; import { FormsModule } from '@angular/forms'; import { IonicModule } from '@ionic/angular'; import { WhenPageRoutingModule } from './when-routing.module'; import { WhenPage } from './when.page'; import {TimeModule} from '../../timemodule/time.module'; @NgModule({ imports: [ CommonModule, FormsModule, IonicModule, WhenPageRoutingModule, TimeModule ], declarations: [WhenPage ] }) export class WhenPageModule {}在另一个模块的一个组件中,我从共享模块导入了该组件,但收到以下错误
in one of the components of the other module i imported the component from shared module, but i receive the below error
import { AddtimeComponent } from '../../timemodule/time.module'
模块在本地声明组件,但不会导出.
module declares component locally, but it is not exported.
推荐答案
您无需再次导入该组件,只需在其他模块中导入SharedModule即可随意使用声明为&&的组件.在SharedModule中导出.
You do not need to import the component again, only import the SharedModule in other modules and feel free to use the component declared && exported in the SharedModule.
import { SharedModule } from '/path/to/SharedModule'; @NgModule({ imports: [ ... SharedModule ] })尝试在Stackblitz中复制此设置,或共享对存储库的访问权限,以便我们调试您的问题并为您提供解决方案.
Try to replicate this setup in a Stackblitz or share access to the repository in order to allow us debug your issue and provide you a solution.
因为您正在尝试在模块的构建过程中引导组件.然后可能需要使用EntryComponent来使组件本身从加载的模块的引导程序中提供.
Since you are trying to bootstrap the Component in the build process of your Module. Then it is possible that you need to use the EntryComponent to make the component itself to be provideed from bootstrap of the module loaded.
在代码中查看它:
import { SharedModule } from '/path/to/SharedModule'; import { AddtimeComponent } from '/path/to/AddtimeComponent'; @NgModule({ imports: [ ... SharedModule ], entryComponents: [ AddtimeComponent ] })有关更多信息,请结帐: codinglatte/posts/angular/entry-components-angular/
For more information, checkout: codinglatte/posts/angular/entry-components-angular/
更多推荐
模块在本地声明组件,但不导出
发布评论