विश्व का सबसे बड़ा हिंदी वेब डेवलपर साइट

AngularJS ng-click Directive


Increase the count variable by one, each time the button is clicked:

<button ng-click="count = count + 1" ng-init="count=0">OK</button>
Try it yourself »

Definition and Usage

The ng-click directive tells AngularJS what to do when an HTML element is clicked.


<element ng-click="expression"></element>

Supported by all HTML elements.

Parameter Values

Value Description
expression An expression to execute when an element is clicked.

More examples


Execute a function, in AngularJS, when a button is clicked:

<body ng-app="myApp">

<div ng-controller="myCtrl">
    <button ng-click="myFunc()">OK</button>
    <p>The button has been clicked {{count}} times.</p>

angular.module('myApp', [])
.controller('myCtrl', ['$scope', function($scope) {
    $scope.count = 0;
    $scope.myFunc = function() {

Try it yourself »