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.

  1. appShell
  2. application
  3. class
  4. component
  5. directive
  6. enum
  7. guard
  8. interface
  9. library
  10. module
  11. pipe
  12. service
  13. serviceWorker
  14. universal
  15. 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