$scope.testObj={};
angular.forEach(results, function (value,index) {
$scope.testObj[index]=value.arr;
console.log($scope.testObj[index]);
console.log(index);
$scope.$watch('testObj',function(newVal, oldVal) {
console.log(newVal, oldVal) ;
},true
);
})
The above code works fine (do not worry about results;it is an array). The problem lies when I am trying that:
$scope.$watch('testObj[index]',function(newVal, oldVal) {
console.log(newVal, oldVal) ;
},true
);
I have no idea why that happens and I am getting undefined from both newVal, oldVal. How may I solve that?
By the way testObj[0] works...
indexto a function arguments, what do you expect bro ?