Please note, this is a STATIC archive of website www.w3schools.com from 05 May 2020, cach3.com does not collect or store any user information, there is no "phishing" involved.
THE WORLD'S LARGEST WEB DEVELOPER SITE

AngularJS ng-click Directive


Example

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.


Syntax

<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

Example

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>
</div>

<script>
angular.module('myApp', [])
.controller('myCtrl', ['$scope', function($scope) {
    $scope.count = 0;
    $scope.myFunc = function() {
        $scope.count++;
    };
}]);
</script>

</body>
Try it Yourself »