Component: Component is the reusable part of the UI(user Interface).
Components can
be kept one inside another called nested component.
To create a component command is:
ng generate component component-name
Nested Components: component Inside another component is called Nested Components
eg: //[Link]
<app-movie></app-movie>
Here app-movie is the child component and [Link] is parent component
Communication between the components:
components can send data from parent to child or child to parent or any other
components too.
Parent to child:
Parent component can send data to child component in two ways
i. @Input
ii. content projection
i.@Input() :
Parent component can send data to child components as attributes/properties but
those values are received by Child components using @Input() decorator
//[Link]
<app-details name="prasad" age="28" ></app-details>
<app-details name="shekhar" age="54" ></app-details>
<app-details name="suresh" age="49" ></app-details>
//[Link]
@Input() name='';
@Input() age=0;
//[Link]
<div>
<h2>{{name}}</h2>
<p>{{age}}</p>
</div>
ii. content-projection: it allows parent component to project some content into
child components template directly using ng-content element
//[Link]
<app-details>
<h2>Prasad</h2>
<p>28</p>
</app-details>
<app-details>
<h2>shekhar</h2>
<p>54</p>
</app-details>
//[Link]
<ng-content></ng-content>