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
3 Answers
Reset to default 17If 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
版权声明:本文标题:javascript - Angular - how to create a child component using Angular CLI - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738552224a2097594.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论