angular - module 在本地声明组件,但未导出

标签 angular typescript ionic-framework ionic4 ng-modules

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

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { DateslideComponent } from './dateslide/dateslide.component';
import { IonicModule } from '@ionic/angular';
import { TimeslideComponent } from './timeslide/timeslide.component';
import { AddtimeComponent } from './addtime/addtime.component'

@NgModule({
   declarations: [DateslideComponent, TimeslideComponent, AddtimeComponent],
   imports: [
       CommonModule,
       IonicModule
   ],
   exports: [DateslideComponent, TimeslideComponent, AddtimeComponent]
})
export class TimeModule { }

在另一个模块中,我导入了共享模块。
 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 {}



在另一个模块的一个组件中,我从共享模块导入了该组件,但我收到以下错误
import { AddtimeComponent } from '../../timemodule/time.module'

module declares component locally, but it is not exported.

最佳答案

您无需在主模块中导入 AddtimeComponent。您必须将其导出到 SharedModule 中,如下所示。

import { AddtimeComponent } from './addtime/addtime.component';
export { AddtimeComponent } from './addtime/addtime.component';
NgModule 装饰器中的导出属性和 header 中的导出是不同的。 NgModule 中的 export 属性用于 Angular 编译器,而 header 中的 export 用于 Typescript 编译器。
如果你打算只使用选择器,那么在 NgModule 装饰器中提及就足够了。如果要在其他模块中导入 Typescript 类,则必须在功能模块中导出该类。

关于angular - module 在本地声明组件,但未导出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60740708/

相关文章:

javascript - 如何在按下回车键时提交的文本区域中添加换行符?

angular - 测试 Angular 2 应用程序时如何正确使用 SharedModules 和 Router?

typescript :同一对象的其他属性引用属性类型

android - 使用imagepicker加载图像时, ionic 应用程序崩溃

javascript - 无法读取未定义错误的属性 'push'?

error-handling - Angular 2. 如何在 Observable 中使用重定向处理 4xx 错误?

Angular 2 : contentChildren communication

javascript - Angular 2 使用现有提供者

css - 在 Ionic Framework 中根据屏幕尺寸制作响应式网格组件

angular - 我不知道为什么我会在 Angular : "ERROR TypeError: Cannot set property ' position' of undefined"中收到此消息