2

I'm using Angular 14. I want to create a project where I can house common models and services used by other projects. I ran this command to create the scaffolding

$ ng generate library my-lib

This produced a directory structure that included

- tsconfig.json
- angular.json
- package.json
- package-lock.json
+ projects
    +   + my-lib
            + src
                ...

How do I generate a model class within that? I tried the below

$ ng generate class=my-lib --type=model --project=my-lib/
An unhandled exception occurred: Schematic "class=my-lib" not found in collection "@schematics/angular".
See "C:\temp\ng-iUC12U\angular-errors.log" for further details.

but I'm not sure what this error means or if I'm even generating a model the right way.

Dave
  • 15,639
  • 133
  • 442
  • 830

1 Answers1

2

Your syntax is incorrect. There are no = used by the CLI. I believe this will do what you intended:

ng generate class my-lib --type model --project finance-uilib-common-service/

If you want to see what the changes will be first without having to create the files, use the --dry-run flag.

Meqwz
  • 1,319
  • 8
  • 14
  • In my project directory, this is creating a file "src/lib/my-lib.my-product.model.ts.ts " (the parameter after class is getting prepended to the model file). Is there any way to have my "my-product.model.ts" file created in a models directory (and also not have ".ts" appended twice)? – Dave Jan 20 '23 at 14:10
  • This answer worked for me - I'd refrain from naming the class the same as the library though, this may be confusing to the cli. – Falcon78 Jan 30 '23 at 07:02