javascript - how to watch an array property of array of array? -


$scope.arr = [ [["ttt", 23],3], [["ppp", 23],3], [["kkk", 23],3] ]; 

i need apply watch on arr[0][0][0] element of array.

rendering arr[0][0][0], arr[1][0][0], arr[2][0][0] in text box using ng-model through ng-repeat arrays.

how apply watch on ng-model variable type in text box?

i tried apply watch on entire array arr didn't trigger below watch function

 $scope.$watch($scope.arr, function (newval, oldval)  {   $log.log(newval); } ); 

html:

<div  ng-repeat="el in arr"> name: <input type="text" ng-model = "el[0][0]" /> </div> 

it seems issue lies in fact new scope being generated each iteration of ng-repeat. around this, can attach separate controller each iteration, explained here.

the simplest way can think of around without multiple controllers utilize ng-change directive, so:

js:

$scope.getchanged = function(newvalue) {   alert('getchanged(), new value: ' + newvalue); } 

html:

<input type="text" ng-model="a[0][0]" ng-change="getchanged(a[0][0])" /> 

here's fiddle showing in action.


Comments