Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular2-分组并有选择地添加模块声明_Angular_Declaration_Angular Cli - Fatal编程技术网

Angular2-分组并有选择地添加模块声明

Angular2-分组并有选择地添加模块声明,angular,declaration,angular-cli,Angular,Declaration,Angular Cli,我们正在使用angular2和AngularCLI,我们的应用程序变得相当大,并且在app.module.ts文件中有大量声明: @NgModule({ declarations: [ GameComponent1, GameComponent2, GameComponent3, StatsComponent1, StatsComponent2, StatsComponent3, AboutPageComponent1, Abo

我们正在使用angular2和AngularCLI,我们的应用程序变得相当大,并且在
app.module.ts
文件中有大量
声明:

@NgModule({
  declarations: [
    GameComponent1,
    GameComponent2,
    GameComponent3,
    StatsComponent1,
    StatsComponent2,
    StatsComponent3,
    AboutPageComponent1,
    AboutPageComponent2,
    AboutPageComponent3,
    AboutPageComponent4,
  ],...
首先,是否有一种方法可以对相关组件声明进行分组,如下所示:

@NgModule({
  declarations: [
    GameComponentsGroup,
    StatsComponentsGroup,
    AboutPageComponentsGroup,
  ],...
然后,对于不同的环境,可以有选择地打开和关闭构建中包含的组件

if(environment.envName == "developmentWithStats")
  appmodule add StatsComponentsGroup
目标是允许在不同的构建中包含不同的功能

我知道我这里缺少一些关键知识,任何帮助都将不胜感激

首先,是否有一种方法可以对相关组件声明进行分组,如下所示:

@NgModule({
  declarations: [
    GameComponentsGroup,
    StatsComponentsGroup,
    AboutPageComponentsGroup,
  ],...
您可以将它们分组到不同的模块中

@NgModule({
  declarations: [ Game1Component, Game2Component ],
  exports: [ Game1Component, Game2Component ]
})
class GameModule {}

@NgModule({
  imports: [ GameModule ]
})
class ModuleThatUsesGameModule {}
然后,对于不同的环境,可以有选择地打开和关闭构建中包含的组件

if(environment.envName == "developmentWithStats")
  appmodule add StatsComponentsGroup
你可以这样做

const declarations = [
  CoreComponent
];

if(environment.envName == "developmentWithStats") {
  declarations.push(SomeComponent);
}

@NgModule({
  declarations: declarations
})
首先,是否有一种方法可以对相关组件声明进行分组,如下所示:

@NgModule({
  declarations: [
    GameComponentsGroup,
    StatsComponentsGroup,
    AboutPageComponentsGroup,
  ],...
您可以将它们分组到不同的模块中

@NgModule({
  declarations: [ Game1Component, Game2Component ],
  exports: [ Game1Component, Game2Component ]
})
class GameModule {}

@NgModule({
  imports: [ GameModule ]
})
class ModuleThatUsesGameModule {}
然后,对于不同的环境,可以有选择地打开和关闭构建中包含的组件

if(environment.envName == "developmentWithStats")
  appmodule add StatsComponentsGroup
你可以这样做

const declarations = [
  CoreComponent
];

if(environment.envName == "developmentWithStats") {
  declarations.push(SomeComponent);
}

@NgModule({
  declarations: declarations
})

哇,这正是我需要的!谢谢你抽出时间回答这个问题哇,这正是我需要的!感谢您抽出时间回答这个问题