Search code examples
angularangular-cliangular-services

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


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.


Solution

  • 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)