• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: I want to pass a an object to a child component. I did everything and nothing works. (ANGULAR)

Resolved: I want to pass a an object to a child component. I did everything and nothing works. (ANGULAR)

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

Question:

This is the parent component: I passed all the data from the parentComponent to main-page Component.
(TEMPLATE)
(TEMPLATE) As you can notice that there’s a click button in which I emitted this method to the parent so I can pass its value to another child component.
I cannot use any value in cartList, why?

Answer:

Input variables, event emitters, and RxJS just complicate the problem here. All you need is a simple Angular service.
Here is a stackblitz: https://stackblitz.com/edit/angular-ivy-a6ub1h?file=src/app/app.component.html
Your parent component doesn’t need any typescript, all it needs to do is instantiate the other components via html:
Parent Component
I’ll make a product service to simulate your app, although I’m not sure exactly what your service looks like. Products will just have a name for simplicity.
Product Service
And I’ll make a service to hold the cart list items, we’ll have add and delete functionality.
Cart Service
Main page just gets the products and can add them to the cart.
Main Page
Cart component shows the cart items and can delete them
Cart List

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.