ng generate class command in Angular CLI

ng generate class command is used to create classes in Angular applications

ng generate class syntax

ng generate class takes class name as parameter.

Additionally we can pass different options as well.

ng generate class [name] [options]

or you can use shorthand syntax

ng generate d [name] [options]

ng generate class arguments

ng generate class takes one argument i.e, name, nothing but class name.

The name type is string.

ng generate class options

ng generate class accepts 3 different types of options.

  1. project
  2. skip-tests
  3. type
OptionDescriptionTypeDefault Value
projectThe name of the project.string
skip-testsDo not create "spec.ts" test files for the new class.booleanfalse
typeAdds a developer-defined type to the filename, in the format "name.type.ts".string

ng generate class example

For example if you want to create a class named product, use ng generate class product command.

CREATE src/app/product.spec.ts (158 bytes)
CREATE src/app/product.ts (25 bytes)
Liked this post? Subscribe