Button Increment/Decrement Value using ng-click

Swappy_Gaj
Posted by Swappy_Gaj under AngularJS category on | Points: 40 | Views : 784
Explanation:
Here we are incrementing and decrementing value using button click using ng-click directive
-----------------------------------------------------------------------------------------------------

<!DOCTYPE html>
<html ng-app="myapp">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title></title>
<link rel="stylesheet" href="">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0-rc.2/angular.js"></script>
</head>
<body ng-controller="ctrl">
{{val}}
<button ng-click="increment()">Increnment</button>
<button ng-click="decrement()">Dcrenment</button>
<script type="text/javascript">
var myapp=angular.module('myapp', []);
myapp.controller('ctrl',function($scope){
$scope.val=0;
$scope.increment=function()
{
$scope.val+=1;

}
$scope.decrement=function()
{
$scope.val-=1;

}

});
</script>
</body>
</html>

Comments or Responses

Login to post response