https://github.com/angular/angular-cli#generating-components-directives-pipes-and-services
Generating Components, Classes, Directives, Guards, Interfaces, Enums, Pipes and Services, Modules, Libraries
You can use the ng generate (or just ng g) command to generate Angular artifacts:
ng generate component my-new-component
ng g component my-new-component # using the alias
components support relative path generation
if in the directory src/app/feature/ and you run
ng g component new-cmp
your component will be generated in src/app/feature/new-cmp
but if you were to run
ng g component ./newer-cmp
your component will be generated in src/app/newer-cmp
if in the directory src/app you can also run
ng g component feature/new-cmp
and your component will be generated in src/app/feature/new-cmp
You can find all possible blueprints in the table below:
Scaffold Usage
Component ng g component my-new-component
Directive ng g directive my-new-directive
Pipe ng g pipe my-new-pipe
Service ng g service my-new-service
**Class ng g class my-new-class**
Guard ng g guard my-new-guard
Interface ng g interface my-new-interface
Enum ng g enum my-new-enum
Module ng g module my-module
angular-cli will add reference to components, directives and pipes automatically in the app.module.ts. If you need to add this references to another custom module, follow this steps:
ng g module new-module
to create a new module
call
ng g component new-module/new-component
This should add the new component, directive or pipe reference to the new-module you've created.