Angular: Empty Fiddle
http://angularjs.org/
by boneskull
HTML
<script src="http://code.angularjs.org/1.1.5/angular.min.js"></script>
<div ng-controller="MyCtrl">
<button ng-click="sections[1] = 'spam'">click me</button>
</div>
JavaScript
var myApp = angular.module('myApp', []);
//myApp.directive('myDirective', function() {});
//myApp.factory('myService', function() {});
function MyCtrl($scope) {
$scope.sections = ['foo', 'bar', 'baz'];
for (var i = 0; i < $scope.sections.length; i++) {
$scope.$watch('sections[' + i + ']', (function (i) {
return function (newval, oldval) {
if (newval !== oldval) {
console.log(i + ' changed from ' + oldval + ' to ' + newval);
}
};
})(i));
}
}