简体   繁体   English

角度不同模块阵列的类型是什么?

[英]What is the type for array of different modules in angular?

In angular 5 core module I'm importing external and internal modules as well. 在角度5核心模块中,我也导入外部和内部模块。

So, I created an array of type any to hold all module objects. 所以,我创建了一个类型为any的数组来保存所有模块对象。 I used that array variable in imports and exports. 我在导入和导出中使用了该数组变量。 My question is instead of any is there are other types we have? 我的问题是,而不是any的是,有其他类型,我们有吗? If So, for MODULES and COMPONENTS what type should come? 如果是这样,对于MODULES和COMPONENTS应该采用什么类型?

const MODULES: any[] = [
  BrowserModule,
  BrowserAnimationsModule,
  HttpClientModule,
  RouterModule,
];

const COMPONENTS: any[] = [
  HeaderComponent
];

const PROVIDERS: Provider[] = [
  NotifyService,
  RouterHelpers
];

@NgModule({
  imports: [
    ...MODULES,
  ],
  declarations: [
    ...COMPONENTS,
  ],
  providers: [
    ...PROVIDERS
  ],
  exports: [
    ...MODULES,
    ...COMPONENTS,
  ]
})

export class CoreModule {
}

from NgModule doc 来自NgModule doc

  • Provider type is Provider[] 提供者类型是Provider[]
  • Declarations type is Array<Type<any> |any[]> 声明类型是Array<Type<any> |any[]>
  • Imports type is Array<Type<any> | ModuleWithProviders |any[]> 导入类型是Array<Type<any> | ModuleWithProviders |any[]> Array<Type<any> | ModuleWithProviders |any[]>
  • Exports type is Array<Type<any> | any[]> 导出类型为Array<Type<any> | any[]> Array<Type<any> | any[]>
  • EntryComponents type is Array<Type<any> | any[]> EntryComponents类型是Array<Type<any> | any[]> Array<Type<any> | any[]>

Using type any[] for modules and components is valid. 对模块和组件使用any[]类型是有效的。 If you want to use something else, you can refer to the NgModule interface, which uses 如果您想使用其他东西,可以参考使用的NgModule接口

  • Array<Type<any> | any[]>; for component declarations 用于组件声明
  • Array<Type<any> | ModuleWithProviders | any[]>; for module imports 用于模块导入

Type is a class from the angular framework ( doc ) Type是角度框架( doc )中的一个类

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM