Example1
AngularJS ng-click example to increment a variable on every click.
<div ng-app="myApp" ng-controller='MyCtrl'> <button ng-click="count = count + 1" ng-init="count=0">Click to increment</button> <div>count: {{count}}</div> </div> <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.3/angular.min.js"></script> <script> var module = angular.module('myApp', []); module.controller('MyCtrl', function($scope) {}); </script>
Example2
AngularJS ng-click example to increment a variable on every click. This time use function “inc” to increment the variable.
<div ng-app="myApp" ng-controller='MyCtrl'> <button ng-click="inc()" ng-init="count=0">Click to increment</button> <div>count: {{count}}</div> </div> <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.3/angular.min.js"></script> <script> var module = angular.module('myApp', []); module.controller('MyCtrl', function($scope) { $scope.inc = function() { $scope.count += 1; }; }); </script>