AngularJS watch object

http://stackoverflow.com/questions/11592538/nested-models-in-angularjs Resources: https://groups.google.com/d/topic/angular/VD77QR1J6uQ/discussion https://groups.google.com/d/topic/angular/-Tx8U9Xm07k/discussion

by suraj mahajan

HTML

<div ng-app="watchApp" ng-controller="watchCtrl">
        <input type="text" ng-model="b.Example" />
    </div>

JavaScript

angular.module('watchApp', []).controller('watchCtrl', function($scope) {
    $scope.count = 0;
    $scope.b = [{value: 1},
    {value: 2},
    {value: 3},
    {value: 4},
    {value: 5},
    {value: 6}];
    
    $scope.b.Example="suraj";

    $scope.$watch('b.Example', function(_old,_new) {
        // do something here
        console.log(_old + ' -- ' + _new);
        $scope.count += 1;
    }, true);
});