With early versions of the Angular Cli when I run ng g service services/MyService
it created:
services/my-service/my-service.service.ts
services/my-service/my-service.service.spec.ts
But now it creates
services/my-service.service.ts
services/my-service.service.spec.ts
Is there a way to go back to the other behavior without write a verbose ng g service services/my-service/MyService ?
I had not found anything related but maybe I am not using the correct keywords.
While you can pass
--flat=false
each time you executeng generate
so that a directory is created based on the service/pipe/directive name, you can actually override default schematics options such asflat
at the project level inangular.json
to avoid needing to pass the--flat=false
option every time on the command line. For example, to setflat
tofalse
when executingng g service services/MyService
, you would add an additional property,@schematics/angular:service
, in theschematics
property of the respective project inangular.json
:After adding this override, running the command
ng g service services/MyService
, generates the following output:You can override any specific schematics you need whether that is for Pipes, Services, Components, Modules, or Directives. You can see the default schematics options at
/node_modules/@angular/cli/lib/config/schema.json
. There are a number of options and you can fine tune exactly what you want generated and how to avoid needing to remember and pass options to the command line.If you have multiple projects, you can create a property
schematics
at the same level asprojects
to override schematic options for all projects.Hopefully that helps!
The
flat
flag defaults totrue
when generating a service.I suggest one of the following (haven't tested on Angular CLI 7 but both work with Angular CLI 6)