SlideShare a Scribd company logo
Data Sharing Between Child
and Parent Components in
AngularJS
https://fibonalabs.com/
Data Sharing Between Child and Parent Components in AngularJS
Introduction
Angular is one of the widely used JavaScript frameworks, written in typescript.
It is a component-based framework which is used for developing SPAs and
large enterprise applications. It was developed by Google in 2009, and as a
result, there have been many iterations. In general, frameworks increase
performance and web development efficiency by providing a consistent
structure for developers. It also offers developers a host of additional features
which can be added to the software/application without any additional effort,
hence saving a lot of development time.
Benefits
● Faster Development Process: It allows the developer to build a highly
efficient application faster with the help of technical advantages that the
angular framework provides like – Angular CLI, Two-Way data binding,
built-in routing, templating and a large developer community which makes
angularJS web development easier.
● Lightweight Web Apps: Earlier performance of large-scale applications
was very poor. Thanks to angular for the lazy-load feature. Which
significantly improves the performance of such large-scale apps by
● Efficient Problem-solving Patterns: It offers an efficient design pattern,
dependency injection and service which helps in solving productivity issues
and speeding up the development process.
● Cross-Platform Development: It also supports cross-platform
development. It allows the developers to write code that can run on
multiple platforms like mobile and web applications.
Sharing Data Between Parent & Child Components
Data sharing between components in angular is an important thing in a
component-based framework. Small components are good to manage in
angular. When we start breaking down the complex requirements into smaller
ones (I.e., smaller components) then it's very important to have a proper data-
sharing mechanism. There are multiple ways in which data is shared between
the components. Few of them are:
1. Parent-to-child component
2. Child to a parent component
3. Sharing data between sibling components
Let us consider the below hierarchy for understanding the purpose
<parent-component>
<child-component></child-component>
</parent-component>
Here <parent-component> serves as a context for the <child-component>
@Input() and @Output() decorators give the child component a way to
communicate with the parent component
@Input(): Lets the parent component pass the data to the child component
@Output(): Using this decorator child component can pass data to the parent
component
Sending data from Parent to Child Component
● Child Component
Create a child component to receive the input from the parent component
@Input() decorator in the child component signifies that it can receive data
from the parent component. @Input() properties can have any type, such
as string, number, object etc.
● Binding the Property in the Parent
● Use the Property in the Child Component
// child.html
Now the data will be available in the child component. By using interpolation
binding syntax we can access the value in the template file.
<p> User: {{name}} </p>
Sending Data from Child to Parent
For sharing data from child to parent we need an output decorator.
Data Sharing Between Child and Parent Components in AngularJS
@Output() decorator allows data to be sent from the child component to the
parent component. This decorator acts as a doorway for the transfer of data.
The child component needs to notify the parent component about the
change/update in data. This can be done by using event emitters.
● Preparing the Child Component for Emitting Data
Whenever the user clicks Submit button, an event is emitted. Which
contains the new user’s name.
The next step is to instruct the child selector in the parent component to
listen to this event. This can be done by event binding.
Data Sharing Between Child and Parent Components in AngularJS
● Configuring the Parent Component to Access the Data from the Child
Now the parent component is aware of the event but we have to create a
method to access the data that the child component is emitting.
//parent.ts
In the parent component, let us create a class with a variable to store the data
and a method that will be invoked whenever the child component emits an
event.
Data Sharing Between Child and Parent Components in AngularJS
Sharing Data Between Sibling Components
This can be achieved by sharing the data from one child to parent by using an
output decorator and event emitter. Once the data is received in the parent
component, we can share it with other child components using the input
decorator. To achieve this we have to follow the first two steps.
THANK YOU

More Related Content

PPTX
Sharing Data Between Angular Components
PDF
UDA-Componentes RUP. Validación
PDF
UDA-Componentes RUP. Tabla Avanzada
PDF
UDA-Componentes RUP. Mantenimiento (v2.1.1 deprecado)
PDF
UDA-Componentes RUP. Formulario
PDF
UDA-Componentes RUP. Tabla (v2.1.1 deprecado)
PDF
UDA-Componentes RUP. Botonera
PDF
Salesforce Field Service Lightning
Sharing Data Between Angular Components
UDA-Componentes RUP. Validación
UDA-Componentes RUP. Tabla Avanzada
UDA-Componentes RUP. Mantenimiento (v2.1.1 deprecado)
UDA-Componentes RUP. Formulario
UDA-Componentes RUP. Tabla (v2.1.1 deprecado)
UDA-Componentes RUP. Botonera
Salesforce Field Service Lightning

What's hot (17)

PDF
Xml transformation-doc
PDF
Angular Dependency Injection
PDF
UDA-Componentes RUP. Pestañas
PDF
A Comprehensive Guide to Salesforce Field Service
PPTX
Set up and utilize internal orders as standard SAP® functionality
DOC
07 Advanced RTF Template Techniques.doc
PPTX
Tackling Salesforce Technical Debt
PDF
UDA-Componentes RUP. Combo
PDF
UDA-Componentes RUP. Diálogo (v2.1.0 deprecado)
DOCX
Fast formula queries for functions, contexts, db is and packages
PPTX
Lightning web component
PDF
Angular routing
PDF
UDA-Componentes RUP. Fecha (v2.1.0 deprecado)
PPTX
Lightning Web Component in Salesforce
PDF
How to make your Eclipse application HiDPI ready!
PDF
Ejemplo de Listado de Cuentas Contables Ampliado en eFactory Software de Cont...
PDF
UDA-Componentes RUP. Reporting
Xml transformation-doc
Angular Dependency Injection
UDA-Componentes RUP. Pestañas
A Comprehensive Guide to Salesforce Field Service
Set up and utilize internal orders as standard SAP® functionality
07 Advanced RTF Template Techniques.doc
Tackling Salesforce Technical Debt
UDA-Componentes RUP. Combo
UDA-Componentes RUP. Diálogo (v2.1.0 deprecado)
Fast formula queries for functions, contexts, db is and packages
Lightning web component
Angular routing
UDA-Componentes RUP. Fecha (v2.1.0 deprecado)
Lightning Web Component in Salesforce
How to make your Eclipse application HiDPI ready!
Ejemplo de Listado de Cuentas Contables Ampliado en eFactory Software de Cont...
UDA-Componentes RUP. Reporting
Ad

Similar to Data Sharing Between Child and Parent Components in AngularJS (20)

PPTX
passDataB_wComponentInAngular.pptx
PDF
Angular2 Development for Java developers
PPT
17612235.ppt
PDF
Angular data binding
PDF
Angular JS2 Training Session #2
PDF
Angular 2 overview in 60 minutes
PPTX
yrs of IT experience in enterprise programming
PDF
Angular 2 - An Introduction
PDF
Angular 4 Data Binding | Two Way Data Binding in Angular 4 | Angular 4 Tutori...
PDF
Build Your Own Angular Component Library
PDF
Carlo Bonamico, Sonia Pini - So you want to build your (Angular) Component Li...
PDF
Angular Rebooted: Components Everywhere
PDF
Angular Rebooted: Components Everywhere - Carlo Bonamico, Sonia Pini - Codemo...
PDF
Angular 2 - The Next Framework
PPTX
Angular 2 KTS
PDF
Angular training-course-syllabus
PDF
Angular 4 for Java Developers
PDF
Capstone ms2
PDF
Commit University - Exploring Angular 2
PDF
Instant download Angular 2 Cookbook Frisbie pdf all chapter
passDataB_wComponentInAngular.pptx
Angular2 Development for Java developers
17612235.ppt
Angular data binding
Angular JS2 Training Session #2
Angular 2 overview in 60 minutes
yrs of IT experience in enterprise programming
Angular 2 - An Introduction
Angular 4 Data Binding | Two Way Data Binding in Angular 4 | Angular 4 Tutori...
Build Your Own Angular Component Library
Carlo Bonamico, Sonia Pini - So you want to build your (Angular) Component Li...
Angular Rebooted: Components Everywhere
Angular Rebooted: Components Everywhere - Carlo Bonamico, Sonia Pini - Codemo...
Angular 2 - The Next Framework
Angular 2 KTS
Angular training-course-syllabus
Angular 4 for Java Developers
Capstone ms2
Commit University - Exploring Angular 2
Instant download Angular 2 Cookbook Frisbie pdf all chapter
Ad

More from Fibonalabs (20)

PPTX
A Complete Guide to Building a Ground-Breaking UX Design Strategy
PPTX
React Class Components vs Functional Components: Which is Better?
PPTX
Measures to ensure Cyber Security in a serverless environment
PPTX
Simplifying CRUD operations using budibase
PPTX
How to implement Micro-frontends using Qiankun
PPTX
Different Cloud Computing Services Used At Fibonalabs
PPTX
How Can A Startup Benefit From Collaborating With A UX Design Partner
PPTX
How to make React Applications SEO-friendly
PDF
10 Heuristic Principles
PPTX
Push Notifications: How to add them to a Flutter App
PPTX
Key Skills Required for Data Engineering
PPTX
Ways for UX Design Iterations: Innovate Faster & Better
PPTX
Factors that could impact conversion rate in UX Design
PPTX
Information Architecture in UX: To offer Delightful and Meaningful User Exper...
PPTX
Cloud Computing Architecture: Components, Importance, and Tips
PPTX
Choose the Best Agile Product Development Method for a Successful Business
PPTX
Atomic Design: Effective Way of Designing UI
PPTX
Agile Software Development with Scrum_ A Complete Guide to The Steps in Agile...
PPTX
7 Psychology Theories in UX to Provide Better User Experience
PPTX
Moving From JavaScript to TypeScript: Things Developers Should Know
A Complete Guide to Building a Ground-Breaking UX Design Strategy
React Class Components vs Functional Components: Which is Better?
Measures to ensure Cyber Security in a serverless environment
Simplifying CRUD operations using budibase
How to implement Micro-frontends using Qiankun
Different Cloud Computing Services Used At Fibonalabs
How Can A Startup Benefit From Collaborating With A UX Design Partner
How to make React Applications SEO-friendly
10 Heuristic Principles
Push Notifications: How to add them to a Flutter App
Key Skills Required for Data Engineering
Ways for UX Design Iterations: Innovate Faster & Better
Factors that could impact conversion rate in UX Design
Information Architecture in UX: To offer Delightful and Meaningful User Exper...
Cloud Computing Architecture: Components, Importance, and Tips
Choose the Best Agile Product Development Method for a Successful Business
Atomic Design: Effective Way of Designing UI
Agile Software Development with Scrum_ A Complete Guide to The Steps in Agile...
7 Psychology Theories in UX to Provide Better User Experience
Moving From JavaScript to TypeScript: Things Developers Should Know

Recently uploaded (20)

PDF
Electronic commerce courselecture one. Pdf
PPTX
Cloud computing and distributed systems.
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Empathic Computing: Creating Shared Understanding
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
MYSQL Presentation for SQL database connectivity
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Machine learning based COVID-19 study performance prediction
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PPTX
Big Data Technologies - Introduction.pptx
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
A Presentation on Artificial Intelligence
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
Electronic commerce courselecture one. Pdf
Cloud computing and distributed systems.
The AUB Centre for AI in Media Proposal.docx
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
gpt5_lecture_notes_comprehensive_20250812015547.pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Empathic Computing: Creating Shared Understanding
20250228 LYD VKU AI Blended-Learning.pptx
Mobile App Security Testing_ A Comprehensive Guide.pdf
Digital-Transformation-Roadmap-for-Companies.pptx
MYSQL Presentation for SQL database connectivity
sap open course for s4hana steps from ECC to s4
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Machine learning based COVID-19 study performance prediction
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Big Data Technologies - Introduction.pptx
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
A Presentation on Artificial Intelligence
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Advanced methodologies resolving dimensionality complications for autism neur...

Data Sharing Between Child and Parent Components in AngularJS

  • 1. Data Sharing Between Child and Parent Components in AngularJS https://fibonalabs.com/
  • 3. Introduction Angular is one of the widely used JavaScript frameworks, written in typescript. It is a component-based framework which is used for developing SPAs and large enterprise applications. It was developed by Google in 2009, and as a result, there have been many iterations. In general, frameworks increase performance and web development efficiency by providing a consistent structure for developers. It also offers developers a host of additional features which can be added to the software/application without any additional effort, hence saving a lot of development time.
  • 4. Benefits ● Faster Development Process: It allows the developer to build a highly efficient application faster with the help of technical advantages that the angular framework provides like – Angular CLI, Two-Way data binding, built-in routing, templating and a large developer community which makes angularJS web development easier. ● Lightweight Web Apps: Earlier performance of large-scale applications was very poor. Thanks to angular for the lazy-load feature. Which significantly improves the performance of such large-scale apps by
  • 5. ● Efficient Problem-solving Patterns: It offers an efficient design pattern, dependency injection and service which helps in solving productivity issues and speeding up the development process. ● Cross-Platform Development: It also supports cross-platform development. It allows the developers to write code that can run on multiple platforms like mobile and web applications.
  • 6. Sharing Data Between Parent & Child Components Data sharing between components in angular is an important thing in a component-based framework. Small components are good to manage in angular. When we start breaking down the complex requirements into smaller ones (I.e., smaller components) then it's very important to have a proper data- sharing mechanism. There are multiple ways in which data is shared between the components. Few of them are: 1. Parent-to-child component 2. Child to a parent component 3. Sharing data between sibling components
  • 7. Let us consider the below hierarchy for understanding the purpose <parent-component> <child-component></child-component> </parent-component> Here <parent-component> serves as a context for the <child-component> @Input() and @Output() decorators give the child component a way to communicate with the parent component @Input(): Lets the parent component pass the data to the child component @Output(): Using this decorator child component can pass data to the parent component
  • 8. Sending data from Parent to Child Component
  • 9. ● Child Component Create a child component to receive the input from the parent component @Input() decorator in the child component signifies that it can receive data from the parent component. @Input() properties can have any type, such as string, number, object etc.
  • 10. ● Binding the Property in the Parent
  • 11. ● Use the Property in the Child Component // child.html Now the data will be available in the child component. By using interpolation binding syntax we can access the value in the template file. <p> User: {{name}} </p> Sending Data from Child to Parent For sharing data from child to parent we need an output decorator.
  • 13. @Output() decorator allows data to be sent from the child component to the parent component. This decorator acts as a doorway for the transfer of data. The child component needs to notify the parent component about the change/update in data. This can be done by using event emitters. ● Preparing the Child Component for Emitting Data Whenever the user clicks Submit button, an event is emitted. Which contains the new user’s name. The next step is to instruct the child selector in the parent component to listen to this event. This can be done by event binding.
  • 15. ● Configuring the Parent Component to Access the Data from the Child Now the parent component is aware of the event but we have to create a method to access the data that the child component is emitting. //parent.ts In the parent component, let us create a class with a variable to store the data and a method that will be invoked whenever the child component emits an event.
  • 17. Sharing Data Between Sibling Components This can be achieved by sharing the data from one child to parent by using an output decorator and event emitter. Once the data is received in the parent component, we can share it with other child components using the input decorator. To achieve this we have to follow the first two steps.