I have a parent component which is a form, but this form has different sections, so I created a Child component for each section of the form. So I need to send values from the child to the parent but I cannot use event binding because I am using (routing) routerLink to display each section, there is no way to pass it through event binding, because they are being displayed when we enter the right path.

Is there any alternative to achieve this behavior?

1

There are 1 best solutions below

2
On

By using services you can exchange values with observables. You basically have an observable and an observer. You inject your serivce via dependency Injection to the .ts files that communicate with eachother. You .next(value) in that .ts file where the value is coming from and then subscribe to it in the receiving .ts file. Once you understand that behaviour, observables make a lot of things easier for you when it comes to communication, plus you will need to learn it anyway when you make http-Requests. Here is a helpfull link: https://medium.com/@luukgruijs/understanding-creating-and-subscribing-to-observables-in-angular-426dbf0b04a3