Component Intercommunication
Learn how to pass data between Angular components using input binding.
We'll cover the following
Angular components expose a public API that allows them to communicate with other components. This API encompasses input properties, which we use to feed the component with data. It also exposes output properties we can bind event listeners to, thereby getting timely information about changes in the state of the component.
Let’s look at how Angular solves the problem of injecting data into and extracting data from components through quick and easy examples in the following sections.
Passing data using an input binding
We will expand our products
module and create a new component that will display the details of a product, such as a name and a price. Data representing the specific product details will be dynamically passed from the product list component.
We will start by creating and configuring the component to display product details:
Note: If you are building the Angular application on your local machine, then execute the Angular CLI command
ng generate component product-detail
inside thesrc\app\products
folder of the project to create the new Angular component.
Open the
product-detail.component.ts
file of the new component and import theInput
artifact from the@angular/core
npm package:
Get hands-on with 1200+ tech skills courses.