Why no Angular-CLI generate command for 'model' in Angular Project?
Because a model is a class, to generate it use --type
option like this:
ng generate class hero --type=model
will result in:
hero.model.ts
ng g class subfolder/yourclass --type=model --skip-tests
will create a class yourclass
in app\subfolder
. If you remove --skip-tests
, you will get an extra file yourclass.model.spec.ts
.
You cannot generate a model directly. Actually model is a class. ng generate allows only following types to generate by default.
- appShell
- application
- class
- component
- directive
- enum
- guard
- interface
- library
- module
- pipe
- service
- serviceWorker
- universal
- webWorker
So in your case you can use --type option to define a generate classes. Let's assume you want a class like bar.foo.ts
You just have to define it with following option.
ng generate class bar --type=foo
in your case you can define a module with this command
ng generate class nameOfYourModule --type=model
It will generate nameOfYourModule.model.ts
Please refer this official documentation of ng generate options for more informations.
Just run in root of project:
ng generate interface your_model_name --type=model
# or in models folder
ng generate interface models/your_model_name --type=model