Angular help us create a robust and real-world application which may have complex architecture. To reduce code and make maintenance efficient, breaking application into multiple and independent working components is very important and basic practice.
This Angular post is compatible with Angular 4 upto latest versions, Angular 7, Angular 8, Angular 9, Angular 10, Angular 11 & Angular 12
Sometimes these modular components are placed in the application at different hierarchies such that any type of relation.
Implementation of data communication or event handling can occur in any direction:
From Parent to Child Component.
From Child to Parent Component.
Between Sibling Components of a Parent.
In this tutorial, we will discuss how to achieve data sharing and event handling techniques between components having above explained relations in Angular application using an example.
Here we will create a demo application where we have a parent component(DashboardComponent) having two child components AddeditpersonComponent and PersonlistComponent
Angular provides @Input and @Output decorators for data and even handling.
@Input decorator helps to pass data to a component using component property binding. The @Output decorator is used to Emit out data out of the component into the parent component using EventEmitter.
Check this working application demo on stackblitz