简体   繁体   中英

Is there a way about how to send a value from the Child component to the Parent component using EventEmitter but without using event binding?

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM