AngularJS Tutorial - Increase value in scope for each click








The following code shows how to Increase value in scope for each click.

Example


<!--from  w  w  w  .j  av a2  s  .  c o  m-->
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.js"></script>
</head>
<body ng-app="myApp">
  <div ng-controller="MyCtrl">
    <a ng-click="inactive = !inactive">toggle active</a>
    inactive={{inactive}}
    <br><input type="text" ng-disabled="inactive" ng-model="input1">
    <br><a ng-click="inactive || (prop1=prop1 + 1)">click to increase</a> {{prop1}}
</div>
<script type='text/javascript'>
var myApp = angular.module('myApp',[]);
function MyCtrl($scope) {
    $scope.inactive= false;
    $scope.prop1 = 1;
}
</script>
</body>
</html>

The code above is rendered as follows: