Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

angular 2 pass variable through component chain

I have a nested chain of components that is at least 4 deep, parent -> child -> grand-child -> great-grand-child. I know how to pass a variable step by step through the chain but I would like to be able to pass it directly from parent to great-grand-child. Otherwise I have to write a fair bit of boilerplate code.

like image 336
John Klippenstein Avatar asked Jul 03 '26 15:07

John Klippenstein


1 Answers

An easier way to circumvent having to pass the data down the components would be to share the data in a service, which can be injected into all relevant components. Just be sure to provide the service at the appropriate level to take advantage of hierarchical dependency injectors.

like image 90
Kevin Kipp Avatar answered Jul 05 '26 04:07

Kevin Kipp



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!