简体   繁体   English

是否有可能(以及如何)在另一个类的app.module中访问NgModule中的声明数组?

[英]Is it possible (and how) to access the declarations array inside NgModule in app.module in another class?

I want to get the declarations array from NgModule in app.module in another class. 我想从另一个类的app.module中的NgModule获取声明数组。 Is this possible? 这可能吗?

@NgModule({
  declarations: [
    AppComponent,
    UserListingComponent,
    NewUserComponent,
  ],

I expect something like: const compArray = NgModule.declarations 我希望类似于:const compArray = NgModule.declarations

Maybe you can do this way 也许你可以这样做

    export declarationsArray = [
        AppComponent,
        UserListingComponent,
        NewUserComponent,
    ]

    @NgModule({
      declarations: declarationsArray,
    })

Then you can import in your component or service like 然后,您可以导入您的组件或服务

let deArray = declarationsArray

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在app.module中的服务内部调用方法-Angular - How to call a method inside of a service in app.module - Angular 如何将app.module分成较小的文件? - How to separate app.module into smaller files? Angular将HttpClient从app.module传递到另一个模块到服务 - Angular Pass HttpClient from app.module to another module to a service 如何从 angular 中的 app.module 调用服务内的方法并使用 Imports 中的值 - How to call a method inside a service from app.module in angular and use the values in Imports 如何在Ionic 3的app.module中获取当前的活动选项卡名称 - How to get the Current Active Tab Name inside app.module in Ionic 3 如何在 Angular 的 app.module 中使用使用条件导出的 class? - How can I use a class that use conditional export in Angular's app.module? 如何从app.module中排除用于生产构建的模块? - How to exclude a module from app.module for production builds? 如何在我的 app.module 中访问 const(不导出 const 变量)变量并从 angular 中的子组件访问它? - How to access const(without export const variable) variable in my app.module and access it from children components in angular? 如何在app.module中配置具有多个父项的子项 - How can I configure child with multiple parents in app.module 如何在Angular 5中的app.module中读取appsettings文件? - How to read appsettings file in app.module in Angular 5?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM