0

So I want to generate an Injectable class with specific type (my-store.store.ts), but this:

ng g class my-store --type=store

Doesn't generate spec file and also doesnt add @Injectable decorator.

I am not using ng g service command, because docs does not provide a --type option for it.

I can add @Injectable by hand, but would like to get spec file automatically.

bigInt
  • 203
  • 5
  • 15

2 Answers2

2

Use --spec flag so your command should be

ng g class my-store --type=store --spec=true
jitender
  • 10,238
  • 1
  • 18
  • 44
  • It works, but you explain how you came up with this? [docs](https://angular.io/cli/generate#class) does not provide `--spec` option for `ng g class`. there is only `--skipTests` which is by default false. Maybe its because my local CLI verson is 6? – bigInt Nov 04 '19 at 09:03
  • 1
    --spec option is listed on doc page but mark as depricated for angular 6+ you need to add schematics https://stackoverflow.com/a/51096430/5621827 – jitender Nov 04 '19 at 10:08
1

You can use the --spec flag, as shown in the anwer by @jitender. Or you can check your angular.json file, for the schematics property.

enter image description here

k.s.
  • 2,964
  • 1
  • 25
  • 27