• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: Is there a way to pass an object using emit to the child component? (Angular)

Resolved: Is there a way to pass an object using emit to the child component? (Angular)

0
By Isaac Tonny on 16/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

I’ve created a button whenever I click on it, it passes all values to this empty object ‘product’. I’m trying to emit this object to the child component, so I can push it inside of the product empty array.
— (template of the component)
—
// another component (child)
— Here is what I did in the child template.
It give me an error saying, “Argument of type ‘Event’ is not assignable to parameter of type ‘Item’. Type ‘Event’ is missing the following properties from type ‘Item’: id, img, name, price, availablengtsc(2345)”

Answer:

If you want to understand how things work in Angular, I suggest following the Angular tutorial.
But here’s a simple example of how you can communicate between components.
Items List Component
You don’t need to add the initial HTML markup outside of the main HTML file which is index.html
Cart Component
Parent Component (responsible for handling the business logic)
Your items list and cart components are dumb components, meaning they don’t know where the data is coming from and they should stay that way (the dumb components are also reusable components). That is the role of the parent component.
The parent is fetching the data through a service and passes it to the items list component through an input. The items list component emits an event when the Add Product button is clicked and sends the result to the parent. The parent is responsible to distribute the selected products to the cart component.

If you have better answer, please add a comment about this, thank you!

angular
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: linq2db throws exception when filtering by nested collection

02/04/2023

Resolved: Table data is coming as empty in React

02/04/2023

Resolved: In a Pinescript v5 Strategy why is my bool not working?

02/04/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.