0

I am looking for a good way of doing this:

  • I'll have a section in app with 'routeroutlet' where every route will contain a question with some answers. User will select an answer.

  • Depending on that answer, in the same time, as a result, in another component that is present every time(apart from routes) a specific square will be colored, known by a value somehow sent by the current route

How can I realize this communication, or if I am looking at it wrong, you are welcome to give another solutions.

PS. Sorry for not editing but I'm writing from phone

!!!Components are siblings, on the same level

sTx
  • 1,213
  • 13
  • 32
  • There are many ways of interacting between components. Take a look here: https://angular.io/docs/ts/latest/cookbook/component-communication.html – Christopher Moore Feb 03 '17 at 17:50
  • I can write a complete plunker for you. Can you tell me what is meant by `known by a value somehow sent by the current route` ? Is this some sort of fixed data like route ID attribute or you want the value of answer which user provided ? – Qaisar Nadeem Feb 03 '17 at 20:20
  • @Qaisar Nadeem - What I'm thinking is to send or emit a route id value, or an route unique value with the answer for which I will know what specific square to paint. It will be sth like this: For /page1 route I'll have a square with id 1. It's just about he concept right now, I didn't implemented anything – sTx Feb 04 '17 at 07:59
  • I would appreciate if you could write a simple example. I'm a newbie to angular, and I spend lot of time looking for simple things resolve too – sTx Feb 04 '17 at 08:00

1 Answers1

2

You would use a service that one components sends the messages through, and the other component(s) subscribe to. Read about it on the Docs. https://angular.io/docs/ts/latest/cookbook/component-communication.html#!#bidirectional-service

Ben Richards
  • 3,437
  • 1
  • 14
  • 18
  • Seen, not tryed yet - my components(routes and result)are on the same level and communicate each other – sTx Feb 03 '17 at 17:26