Read and List all exports of an angular module

2020-02-15 02:48发布

The initial situation is as follows: In the node_moduls folder of my project there is a module called @example with some components I want to use in the application. The amount of components varies therefore it´s necessary to state dynamically which components are included inside the module. The example.module.ts file looks like this:

import { NgModule } from '@angular/core';
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
import { FirstModule } from 'EXAMPLE_PATH';
import { SecondModule } from 'EXAMPLE_PATH';
import { ThirdModule } from 'EXAMPLE_PATH';
import { FourthModule } from 'EXAMPLE_PATH';


const MODULES = [
  FirstModule,
  SecondModule,
  ThirdModule,
  FourthModule 
];

@NgModule({
  imports: [NgbModule.forRoot(), ...MODULES],
  exports: [NgbModule, ...MODULES],
  providers: [ExampleService]
})
export class ExampleModule {
}

The MODULES array contains all the components which are included. As usually the module gets imported into the app with following app.module.ts

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { ExampleModule } from '@example/example-module';

import { AppComponent } from './app.component';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    ExampleModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { 
}

Is it possible somehow to determine inside the app which components the exampleModule exports or rather the app imports from this module?
So at the End in this example the app should know that FirstModule, SecondModule, ThirdModule and FourthModule are imported and could be used.

标签: angular npm
0条回答
登录 后发表回答