AngularJS Tutorial - ng-click counter








The following code shows how to create a counter based on ng-click.

Example


<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.js"></script>
</head><!--from   ww  w.ja va  2 s  . c  o  m-->
<body>
  <div ng-app="">
  <div ng-click="count = count + 1" ng-init="count=0">
    Click to Increment
      <div ng-click="count = count - 1; $event.stopPropagation();">Click to Decrement</div>
  </div>
  count: {{count}}
</div>
</body>
</html>

The code above is rendered as follows: