不导入就无法访问功能模块

cannot access feature modules without importing

我们正在使用 Angular6 构建一个 MEAN 网络应用程序。 我们有某些功能模块,比方说 FormGeneratorModule 和 GridGeneratorModule。

我们想要的是,这些应该只在根 appModule 中导入一次,所有其他子模块应该可以直接访问它,即,不必在将要使用它们的每个子模块中导入它们.

我已经对其进行了研究并相应地实现了这些功能模块(导出将要使用的组件和所有内容)。我还在根模块中导入了 BrowserModule,在所有子模块中导入了 CommonModule(用于延迟加载)。但这似乎仍然不起作用,每当我在不同的模块中使用它们时,我仍然必须导入这些功能模块。这完全不可取,因为这些模块非常重。

为了参考,我在这里放了一些代码片段:

root AppModule.ts

import { BrowserModule } from '@angular/platform-browser';
import { NgModule as NgController, NO_ERRORS_SCHEMA, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
import { ModuleWithProviders } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { HttpClientModule } from '@angular/common/http';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';

import { HomeComponent } from '@L3Modules/default/controllers/home/home.component';
import { FormsModule } from '@L3Modules/default/controllers/forms/forms.module';
import { FormGeneratorModule } from '@L3Modules/core/controllers/formGenerator/formGenerator.module';
import { GridGeneratorModule } from '@L3Modules/core/controllers/gridGenerator/gridGenerator.module';


const routing: ModuleWithProviders = RouterModule.forRoot(routes);
@NgController({
  declarations: [
    HomeComponent
  ],
  imports: [
    BrowserModule,
    routing,
    HttpClientModule,
    BrowserAnimationsModule,
    FormsModule,
    FormGeneratorModule,
    GridGeneratorModule,
    NgbModule.forRoot()
  ]
})

功能模块:

formGenerator.module.ts:

@NgModule({
imports: [
    CommonModule,
    ReactiveFormsModule,
    routing,
    NgbModule,
],
declarations: [
    FormGeneratorComponent,
   ...
],
exports: [
    ...ALL the components
],
entryComponents: [
    BComponent,
    AComponent,
    DComponent,
    ...

],
providers: [DService],
schemas: [NO_ERRORS_SCHEMA, CUSTOM_ELEMENTS_SCHEMA]

gridGenerator.module.ts:

declarations : [
    ChComponent,
    PUComponent,
    DTComponent,
],
imports : [
    CommonModule,
    ReactiveFormsModule,
    NgbModule,
    FormsModule
],
exports: [DTComponent],
providers: [],
entryComponents: [],
schemas: [NO_ERRORS_SCHEMA]

如果有人能在这里帮我一下,那就太好了,我想不出我遗漏了什么,以避免在每个使用它们的模块中导入这些巨大的功能模块。提前致谢。

您可以简单地将 AppModule 导入每个功能模块:

formGenerator.module.tsgridGenerator.module.ts

import { AppModule } from './../app.module';

@NgModule({
  imports: [
    AppModule
    ...
  ]

值得注意的是,这样做没有性能优势