Angular CLI Basics - ng generate component


In this video, we cover how to generate components using the Angular CLI. To generate a component, you need to run the following command:

ng generate component component-name

You can add a number of flags after the component name, depending on what you need. The flags we covered in this section are:

  • --export
  • --module
  • --prefix
  • --selector

In addition to the --module flag, which adds a component to a module, you can add a component to a module by putting the component in the folder of a module, closest to where the module is located. So, if you have a SharedModule in a shared folder, you can add a component to that module with the following command:

ng g c shared/component-name

For more information on generating components, and for a list of all the flags available when generating components, you can check out the docs.

If you'd like to learn more about components in Angular, including how to use them and their role in an application, read this section of the Angular documentation.