-routing-scope在Angular CLI中代表什么

Tuk*_*kan 7 angular-cli angular angular-cli-v6

在角度CLI中创建模块时,我们可以添加--routing-scope作为参数.

ng g m dashboard --routing-scope something-here --routing
Run Code Online (Sandbox Code Playgroud)

使用此命令时,我收到错误:

Schematic input does not validate against the 
Schema: {"routingScope":"dashboard","routing":false,"spec":true,"flat":false,"commonModule":true}
Errors: Data path ".routingScope" should be equal to one of the allowed values.
Run Code Online (Sandbox Code Playgroud)

但是允许的值是多少?

文档中未描述此参数.

R. *_*rds 12

经过一番挖掘,我发现了这个:schema.json,CLI 的schema.json.这里有很多好东西.

根据这个,有效值--routing-scopeChild,或Root.套管很重要.默认是Child.

奇怪的是,无论我使用什么值,生成的代码看起来都完全相同.他们俩是什么样子运行后下面是ng g m testing --routing-scope Childng g m testing --routing-scope Root

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';

@NgModule({
  imports: [
    CommonModule
  ],
  declarations: []
})
export class TestingModule { }
Run Code Online (Sandbox Code Playgroud)

进一步挖掘表明,在生成代码以在模块中构建forRootforChild运行函数时使用该值imports.

  • 好的。所以基本上 forRoot 在使用 `ng new projectName --routing` 和使用 `--routing` 参数创建子模块时无论如何都会使用 Child 是默认值,这完全有道理。谢谢! (3认同)