How do you generate services etc. for a @nrwl/nx angular-cli app?

Viewed 6910

Normally when using @angular/cli to develop an application, you add a new service in the following manner:

ng generate service foo

This would generate "FooService".

My question is, when you have generated a library using @nrwl/nx, how do you add a service to it?

ng generate lib foo-lib

What I want to know, is the command to generate service "foo", so that it lives in the foo-lib library.

3 Answers

For nx vesion 6.1, this is the right way:

ng g service my-service --project=myNameOrLibName

Nx is a wrapper around angular cli. Everything you do using Angular-cli, you pretty much do in nx workspaces. Only difference being the custom schematic that nx provides that helps you achieve mono-repo and re-use code across multiple apps within your company. When in doubt, just run any commands with --dry-run and see if things being generated are the things you want and you should be good.

Related