Friday, 23 August 2013

Can someone explain this angular code?

Can someone explain this angular code?

app = angular.module('app', []);
app.controller('MainCtrl', function($scope) {
$scope.updated = 0;
$scope.stop = function() {
textWatch();
};
var textWatch = $scope.$watch('text', function(newVal, oldVal) {
if (newVal === oldVal) { return; }
$scope.updated++;
});
});
<body ng-controller="MainCtrl">
<input type="text" ng-model="text" /> {{updated}} times updated.
<button ng-click="stop()">Stop count</button>
</body>
and http://jsbin.com/emenuf/3/edit
and i have a question,why after i click the button and type {{updated}}
doesnt update?

No comments:

Post a Comment