-
-
Save sortofsleepy/05887f8c35e6031c1b70 to your computer and use it in GitHub Desktop.
$watch testing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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