Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To create a child component with Angular CLI in Angular, follow these steps:

  1. Open your terminal and navigate to the root of your project.

  2. Run the command ng generate component <component-name> where <component-name> is the name of your child component.

  3. This will create a new folder in your src/app directory with the name you specified, containing the files for the new child component.

  4. In the parent component where you want to use the child component, import the child component by adding import { <component-name> } from './<component-name>/<component-name>.component' at the top of the parent component's .ts file.

  5. Add the child component to the parent component's @NgModule declaration by adding <component-name> to the declarations array.

  6. In the parent template where you want to use the child component, insert the child component tag by adding <app-<component-name></app-<component-name>> to the parent component's HTML file.

  7. Save your changes and run your Angular application. Your child component should now be visible within the parent component.