admin管理员组

文章数量:1201801

I have created an Angular app using Angular CLI and created one component: ng g c parent.

How do I create child components (e.g. child1 and child2) and integrate them with a parent using angular CLI?

I am trying to create a simple example and understand in some example parent-child component relationship.

I have created an Angular app using Angular CLI and created one component: ng g c parent.

How do I create child components (e.g. child1 and child2) and integrate them with a parent using angular CLI?

I am trying to create a simple example and understand in some example parent-child component relationship.

Share Improve this question edited Jan 3, 2019 at 20:07 Dale K 27.2k15 gold badges55 silver badges82 bronze badges asked Jan 3, 2019 at 18:22 JoeJoe 13.1k39 gold badges122 silver badges200 bronze badges 2
  • 1 this tutorial may be helpful: tektutorialshub.com/adding-child-component-angular-2 – Rich Commented Jan 3, 2019 at 18:29
  • You can simply create a component with angular CLI. depending on your requirements you can use that component as a child component using input/output parameters. There is no out of the box 'child ' component. – Iman Commented Jan 3, 2019 at 18:35
Add a comment  | 

3 Answers 3

Reset to default 17

If you mean to nest the components into the parent you can do it like this

ng generate component parent/child1
ng generate component parent/child2

This generates the child components inside the parent folder. I do this in my apps to keep together what belongs together! Hope it helped

you can create as many as component you want

ng g c child1
ng g c child2

Then you need to add them in the Html of ParentComponent

<app-child1></app-child1>
<app-child2></app-child2>

and then using @Input and @Output to pass data between parent and child

You can see child routing configuration y child routing component in Angular.io.

angular.io router

本文标签: javascriptAngularhow to create a child component using Angular CLIStack Overflow