I want to get and set the object data in different component in angular.
So which is the best way to do that?
I want to get and set the object data in different component in angular.
So which is the best way to do that?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Aman GuptaPosted Feb 1, 2023, 4:24 PM
Data Sharing Between Angular Components
Parent to Child: via Input
Child to Parent: via Output() and EventEmitter
Child to Parent: via ViewChild
Unrelated Components: via a Service
Anupam MaitiPosted Feb 1, 2023, 12:49 PM
There are multiple ways we can share data between components, like -
1. Using Input and Output decorators where parent-child component relationship are there.
2. Using NgRx module where centralize data store for sharing data and state management are needed.
3. Using shared service to hold data in a single place and allow components to subscribe to that data
So, Best method will be specific to use cases.