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.
- project
- skip-tests
- type
| Option | Description | Type | Default Value |
|---|---|---|---|
| project | The name of the project. | string | |
| skip-tests | Do not create "spec.ts" test files for the new class. | boolean | false |
| type | Adds 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)