Search code examples
angular-clinrwl

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


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.


Solution

  • It just works with the angular-cli command, but you have to add the --app flag

    ng g service foo --app=foo-lib
    

    It is also mentioned in the docs of Nx under "Leverage the AngularCLI".