1

I am not sure if I should use @Input and @Output​ since I think these decorators only work when you wan to communicate a component parent with a child one or vice versa. Can you please clarify it or correct me?

I have 3 components that are in the same level and I am looking for setting a value to a variable from component A in component B. They do no have any relationship.

Thanks

2

1 Answer 1

1

In short, you are right, Input() and Output() only communicate with the parent component. Your parent component could however use the Output() of component B and pass it to the Input() of component A. Using the angular life cycle hook ngOnChanges would aid with that.

There are also many ways to achieve Component A modifying a value in Component B. You could use subjects, services, parent components, as well as many other strategies. This might get into the question of how you want to manage state in your application. https://bertrandg.github.io/angular2-application-state-management-strategy/

At scale, you definitely want to be consistent with state management in your app. ngrx (https://github.com/ngrx) provides a great redux-like strategy

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.