What does --routing-scope stands for in Angular CLI
Asked Answered
C

1

14

In angular CLI when creating module we can add --routing-scope as a parameter.

ng g m dashboard --routing-scope something-here --routing

when using this command I get error:

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.

But what are the allowed values?

This parameter is not described in the docs.

Copycat answered 2/7, 2018 at 13:52 Comment(4)
Maybe check out the docsBolter
@Li357 It's not described in the docsCopycat
@Copycat , they are mentioned here : github.com/angular/angular-cli/wiki/generate-moduleSilt
@Silt yes but "The scope for the generated routing." is all what is written and what I could deduce from the parameter name but it's still not fully clear. Is it the name of the root in main rooting configuration or something different? I tried multiple values and combinations and all of them are returning the above mentioned error.Copycat
D
24

After some digging, I found this: schema.json, the schema.json for the CLI. Lots of good stuff in this.

According to this, the valid values for --routing-scope are either Child, or Root. Casing matters. The default is Child.

An odd thing is, the code that gets generated looks exactly the same no matter what value I use. They both look like what is below after running ng g m testing --routing-scope Child or ng g m testing --routing-scope Root

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

@NgModule({
  imports: [
    CommonModule
  ],
  declarations: []
})
export class TestingModule { }

Further digging shows that the value is used when code is generated to build the forRoot or forChild function in module imports.

Dromedary answered 2/7, 2018 at 14:15 Comment(1)
Ok. So basically forRoot is used anyways when using ng new projectName --routing and when creating submodule with --routing parameter the Child is the default value and this totally makes sense. Thanks!Copycat

© 2022 - 2024 — McMap. All rights reserved.