I have a directive that uses custom template, and I would like to pass the data from that directive to another one, and looking for the best possible way. So, I would like when the data inside the directive one changes, directive two get notified(watcher?), and acts upon it. So far, only the method with controller inside the directive one, and a watcher inside directive two for the controller method(from directive one) makes sense. Is there a a better way for this ?
-------------- --------------
| directive 1 |---data-->| directive 2 |
| | | |
--------------- --------------
You can use the $broadcast on the rootScope:
On the first directive:
On the other directive:
Take a look at this Understanding Angular’s $scope and $rootScope event system $emit, $broadcast and $on
You can use either $broadcast or services
if you want to use values of one directive into another then
second directive