ng-click
ng-dbl-click
ng-mousemove
ng-mouseover
ng-mouseup
ng-mousedown
ng-mouseenter
ng-mouseleave
ng-keyup
ng-keydown
ng-keypress
ng-change
ng-blur
ng-copy
ng-cut
ng-paste
ng-focus
ng-click
directive.
[html]
<!DOCTYPE html>
<html lang="en-US">
<head>
<title>ng-click directive</title>
<script data-require="angular.js@1.3.14" data-semver="1.3.14" src="https://code.angularjs.org/1.3.14/angular.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
<script src="App.js"></script>
<script src="Controller.js"></script>
</head>
<body ng-app="spApp">
<h1>ng-click directive</h1>
<div ng-app="spApp" ng-controller="SPController">
<div ng-click="data.onClick()">Click here</div>
</div>
</body>
</html>
[/html]
[javascript]
angular.module("spApp", [])
.controller("SPController", function($scope) {
$scope.data = {};
$scope.data.onClick = function() {
alert("clicked");
}
} );
[/javascript]
When clicked on the inner div
in the above example, the function data.onClick()
is called.the data
object has a onClick()
function added to it in the controller function. Below is the result.
The controller function adds event listener functions called to the $scope
object.
Output:
When Clicked on "Click Here", the below output appears.
$event,
.This $event acts as parameter to the event listener function. The $event
variable contains the original browser event object.