AngularJS Example:

Watcher on dataset_wc

by sathish panduga p

HTML

<div ng-app>
  <h2>Trying to apply watcher to my dataset</h2>
  <div ng-controller="TodoCtrl">
  <ul>
      <li ng-repeat="col in dataset_wc">
          <input type="text" ng-model="col.name" />
          <input type="text" ng-model="col.value" />
      </li>
      </ul>
  </div>
</div>

CSS

</style> <!-- Ugly Hack due to jsFiddle issue: http://goo.gl/BUfGZ --> 
<link rel="stylesheet" href="http://twitter.github.com/bootstrap/assets/css/bootstrap.css">
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.4/angular.min.js"></script>
<style>
.done-true {
  text-decoration: line-through;
  color: grey;
}

JavaScript

function TodoCtrl($scope) {
  $scope.dataset_wc = {
                d0: { id: 0, name: 'Housing', value: 1 },
                d1: { id: 1, name: 'Movies', value: 1 },
                d2: { id: 2, name: 'Banking', value: 1 },
                d3: { id: 3, name: 'Entertainment', value: 1 },
                d4: { id: 4, name: 'Food', value: 1 }
            };
  
    $scope.$watch('dataset_wc', function(newVal) {
        alert('columns changed');
    },true);
}