I'm looping through a result set and dynamically creating model values, such as:
angular.forEach(users, function(user) {
$scope.usersModels.online[user.id] = 0;
$scope.usersModels.online[user.id]['checked'] = 'checked';
$scope.$watch('usersModels.online[user.id]', function(val) {
console.log(val);
});
});
I'm also trying to watch the change of these models and get the value. This doesn't work however, any ideas what's wrong?
Thanks!
EDIT:
angular.forEach(users, function(user) {
$scope.usersModels.online[user.id] = {};
$scope.usersModels.online[user.id]['value'] = 0;
$scope.usersModels.online[user.id]['checked'] = 'checked';
$scope.$watch(function() {
return $scope.usersModels.online[user.id]['value'];
}, function(val) {
console.log(val);
});
});
$scope.usersModels.online[1] = 0;implies the property is pointing a primitive type, 0. But then comes$scope.usersModels.online[user.id]['checked'] = 'checked';and all the sudden you are treating the same property as if it was an object , which has a property namedchecked. It could very well be a typo. Either way, please have that fixed first.