When should you use @Input vs an @Injectable in an Angular 2 project? For example, if I have an object (with no methods) that multiple components make changes to, I can either:
How do you decide which way to go? Especially since with Injectables you don't have to deal with the hierarchy of how to pass the input data to the child component.
Unless its a very simple object, I would almost always lean towards using an Injectable class and dependency injection. Inputs aren't resolved until the first ngOnInit() lifecycle hook so at the very least an Injectable class will provide more predictable behavior. Creating chains of inputs to pass something down multiple levels is a good sign you should use a service / injectable instead. Using an injectable class you can just inject it wherever you need it without having to worry about the parent component having it as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With