模块在本地声明组件,但不导出

编程入门 行业动态 更新时间:2024-10-28 08:29:10
本文介绍了模块在本地声明组件,但不导出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我创建了一个共享模块,并声明了&在其他模块中导出了我需要的组件.

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/

更多推荐

模块在本地声明组件,但不导出

本文发布于:2023-07-12 07:28:16,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1096860.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:但不   组件   模块   声明

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!