what is ng-click

Ng-click directive provides the custom behaviour when an element is clicked. When elements clicked, it will call the event handler function, which bind to ng-click.

Example of ng-click

In the following example, we perfume the sum of two numbers on button click event.

		
<!DOCTYPE html>
<html>
<head>
<script src="angular.js"></script>
<script>
    var x=angular.module('abc',[]).controller('abc1',function($scope){
    $scope.add=function(n1,n2){
    $scope.data=parseInt(n1)+parseInt(n2);
    }
    
    });
  </script>  
</head>
<body ng-app='abc'>
    <div ng-controller='abc1'>
 enter 1st value:   <input type="text" ng-model='n1'><br>
 enter 2nd value:   <input type="text" ng-model='n2'><br>
 <input type="button" value="sum" ng-click='add(n1,n2)'>
<div>
        {{data}}
        </div>    </div>
</body>
</html>

		
		

It will show the following output:-

		
		what is ng-click
		Figure 1
		
		

Similarly, we can also use ng-dblclick directives and it will perfume it but on double click.