What is the difference between child and parent component in angular 2,
Specifically what are parent components and child components, hate that all the tutorials, documentation nods over this, build an angular 2 app and understand which components, however, read about how to pass data between components all references refer to " interaction with child / parent components "which is impossible to get if in my case I don't know the difference between them.
source to share
A parent component is a component with a wider scope, and a child component is a component that is different from this scope, but not all. One example is an html page with a toolbar, content area, and table inside the content area.
If we look at the pseudo html, it looks like this:
<html>
<toolbar></toolbar>
<content>
<table></table>
</content>
</html>
When we look at this, we say which content
is a parent component that has a child table
and toolbar
is sibling to content
.
Let's say that it content
has some data that it wants to pass to rendering in table
, and then in the parent component (content), you have to write the necessary logic so that this data binds it to a variable, and then in the html template property binds this variable to table
so that it could be visualized.
Pseudo html again:
<html>
<content>
<table [tableData]="contentData"></table>
</content>
</html>
Hope this is clear and helps
source to share