Angular cli service generation: service is generated in root instead of /services

Mike Bovenlander picture Mike Bovenlander · Oct 7, 2016 · Viewed 21.2k times · Source

I'm messing around with Angular a bit. Trying to generate some stuff with angular-cli. But when generating a new service the service is placed in "/src/" folder.

I would like to set a global default folder for this. Is there a config setting where I can do something like: { servicesDir: "/src/services/" }?

I'm using ng generate service Test as command.

Answer

Meir picture Meir · Oct 7, 2016

the cli can take a directory, which in the latest release is also a module, hence use:

ng generate service services/Test

Following the comment below, you might need to first run:

ng generate module services

or

mkdir src/services (or src/app/services, depending on your file structure)