I am trying to distinguish between an internal change and an external change with a two-way data-bound attribute ( '=' ).
In other words: I do not want $watch run the value if the change was internal (i.e. the region variable was changed in the controller or in the communication function).
Here is some code that illustrates my problem:
HTML
<div ng-app="myApp"> <div ng-controller="MainCtrl"> <input ng-model="value"/> <mydemo value="value"></mydemo> </div> </div>
Javascript
app.directive('mydemo', function () { return { restrict: 'E', scope: { value: "=" }, template: "<div id='mydiv'>Click to change value attribute</div> Value:{{value}}", link: function (scope, elm) { scope.$watch('value', function (newVal) {
Live demo: http://jsfiddle.net/B7hT5/11/
Any idea I can tell?
source share