0

I've been attempting to accomplish this for quite some time (Angular 1.5) and I don't see any clean, reliable way of having two components react to one another without using:

A) $broadcast events where Component A broadcasts an event which Component B catches and responds to. I don't like this approach as it pollutes Component B with specific event handlers of Component A.

B) Sharing data via service or bindings with $watches placed on it to detect and respond to changes.

From my perspective it'd seem like the best approach would be compositional in that I could have a parent component which contains both Component A and B. Component A could emit an event that the parent component could catch and at that point call a method directly on component B's API. However, this does not seem to be possible with isolate scope components.

Any advice on how to have a function called on Component B when Component A does a particular action (in a loosely coupled manner) would be greatly appreciated.

Thank you

Lee J.
  • 1
  • What is the relationship of the two components? Are they siblings? Or parent and child? In Model-View frameworks, the Model is the single source of truth and events change the model. Refactor the model so that events get don't need to be shared between siblings. – georgeawg Feb 17 '17 at 02:42
  • For advice on handling events without using watchers, look at -- [AngularJs 1.5 - Component does not support Watchers, what is the work around?](http://stackoverflow.com/questions/35534479/angularjs-1-5-component-does-not-support-watchers-what-is-the-work-around/35535336#35535336) – georgeawg Feb 17 '17 at 02:46

0 Answers0