title: Angularjs dynamically create models
body: <p>I'm looping through a result set and dynamically creating model values, such as:</p>
  
  <pre><code>     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);
  
             });
       });
  </code></pre>
  
  <p>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?</p>
  
  <p>Thanks!</p>
  
  <p>EDIT:</p>
  
  <pre><code>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);
         });
   });
  </code></pre>