Skip to content

Instantly share code, notes, and snippets.

@sortofsleepy
Created July 22, 2014 01:16
Show Gist options
  • Save sortofsleepy/05887f8c35e6031c1b70 to your computer and use it in GitHub Desktop.
Save sortofsleepy/05887f8c35e6031c1b70 to your computer and use it in GitHub Desktop.
$watch testing
<div ng-app="watchApp" ng-controller="watchCtrl">
<div ng-repeat="a in b">
<input type="text" ng-model="a.value" />{{a.value}}
</div>
<div ng-repeat="a in c">
<input type="text" ng-model="a.value" />{{a.value}}
</div>
<div id="test"></div>
</div>
angular.module('watchApp', []).controller('watchCtrl', function($scope) {
$scope.count = 0;
$scope.b = [{value: 1},
{value: 2},
{value: 3},
{value: 4},
{value: 5},
{value: 6}];
$scope.c = [
{value:"a"},
{value:"b"},
{value:"c"},
{value:"d"},
{value:"e"},
{value:"f"}
];
$scope.$watch('c', function() {
// do something here
if($scope.count > 1){
$scope.b[0].value = "TWENTY";
}
$scope.count += 1;
}, true);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment