Maciek Drabicki
Maciek Drabicki

Reputation: 439

How to push object to array from another component?

I have component review with array Reviews and component CreateReview with form to create new review. At this moment this two components are on this same page so i wish to could push new element from CreateReviewComponent on array from ReviewComponent to show all reviews with new one. How to do that?

Upvotes: 1

Views: 689

Answers (1)

Octavio Garbarino
Octavio Garbarino

Reputation: 782

You could have your array of reviews in a service, and in ReviewComponent display the reviews obtained in that service. And in form of the CreateReviewComponent, if all is ok, call the same service to add the new review to the list. If both components have the service injected, both of theme will share the same instance of the service and the list of reviews will be the same.

I hope this helps!

Upvotes: 1

Related Questions