Angular - how to create a child component using Angular CLI
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.
javascript node.js angular
add a comment |
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.
javascript node.js angular
1
this tutorial may be helpful: tektutorialshub.com/adding-child-component-angular-2
– Rich
Jan 3 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
Jan 3 at 18:35
add a comment |
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.
javascript node.js angular
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.
javascript node.js angular
javascript node.js angular
edited Jan 3 at 20:07
Dale Burrell
3,41352655
3,41352655
asked Jan 3 at 18:22
JoeJoe
1,74031637
1,74031637
1
this tutorial may be helpful: tektutorialshub.com/adding-child-component-angular-2
– Rich
Jan 3 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
Jan 3 at 18:35
add a comment |
1
this tutorial may be helpful: tektutorialshub.com/adding-child-component-angular-2
– Rich
Jan 3 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
Jan 3 at 18:35
1
1
this tutorial may be helpful: tektutorialshub.com/adding-child-component-angular-2
– Rich
Jan 3 at 18:29
this tutorial may be helpful: tektutorialshub.com/adding-child-component-angular-2
– Rich
Jan 3 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
Jan 3 at 18:35
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
Jan 3 at 18:35
add a comment |
3 Answers
3
active
oldest
votes
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
add a comment |
You can see child routing configuration y child routing component in Angular.io.
angular.io router
add a comment |
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
Can I createparent1/child1
andparent2/child1
orchild1
must be unique every time? (even though it is underparent1
andparent2
)
– Joe
Jan 3 at 20:48
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54027774%2fangular-how-to-create-a-child-component-using-angular-cli%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
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
add a comment |
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
add a comment |
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 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
answered Jan 3 at 18:29
RezaRahmatiRezaRahmati
7,70823280
7,70823280
add a comment |
add a comment |
You can see child routing configuration y child routing component in Angular.io.
angular.io router
add a comment |
You can see child routing configuration y child routing component in Angular.io.
angular.io router
add a comment |
You can see child routing configuration y child routing component in Angular.io.
angular.io router
You can see child routing configuration y child routing component in Angular.io.
angular.io router
answered Jan 3 at 18:38
Chester mi niñoChester mi niño
3115
3115
add a comment |
add a comment |
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
Can I createparent1/child1
andparent2/child1
orchild1
must be unique every time? (even though it is underparent1
andparent2
)
– Joe
Jan 3 at 20:48
add a comment |
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
Can I createparent1/child1
andparent2/child1
orchild1
must be unique every time? (even though it is underparent1
andparent2
)
– Joe
Jan 3 at 20:48
add a comment |
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
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
edited Jan 3 at 22:10
Yashwardhan Pauranik
2,14611731
2,14611731
answered Jan 3 at 18:34
ExactPauseExactPause
16828
16828
Can I createparent1/child1
andparent2/child1
orchild1
must be unique every time? (even though it is underparent1
andparent2
)
– Joe
Jan 3 at 20:48
add a comment |
Can I createparent1/child1
andparent2/child1
orchild1
must be unique every time? (even though it is underparent1
andparent2
)
– Joe
Jan 3 at 20:48
Can I create
parent1/child1
and parent2/child1
or child1
must be unique every time? (even though it is under parent1
and parent2
)– Joe
Jan 3 at 20:48
Can I create
parent1/child1
and parent2/child1
or child1
must be unique every time? (even though it is under parent1
and parent2
)– Joe
Jan 3 at 20:48
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54027774%2fangular-how-to-create-a-child-component-using-angular-cli%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
this tutorial may be helpful: tektutorialshub.com/adding-child-component-angular-2
– Rich
Jan 3 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
Jan 3 at 18:35