I am looking for an optimal solution to avoid use $scope.$watch
, given the following use case:
1) directiveA
has the following scope:
{ sharedModel : '=' }
2) for your own use, directiveA
you need to change your internal variable with a name modelA
based on sharedModel
.
3) directiveB
uses directiveA
and binds sharedModel
to modelB
(its internal model).
<directive-a
shared-model="vm.modelB" />
4) When modelB
/ changes sharedModel
, I would like it to be modelA
updated (remember, the modelA
data is obtained only from sharedModel
).
To execute # 4, I could add $scope.$watch
in sharedModel
. However, it $watch
is expensive and not amenable to testing. Any recommendations best?
EDIT:
for an example with live code see jsfiddle . note the $scope.$watch
line # 10 that I want to replace.
source
share