English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

AngularJS ng-mousedown directive

AngularJS Reference Manual

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="https://cdn.staticfile.org/angular.js/1.4.6/angular.min.js"></script>
</head>
<body ng-app="">
<div ng-mousedown="count = count + 1" ng-init="count=0">Click me!/div>
<h1>{{count}}</h1>
<p>This example demonstrates that when the mouse is pressed on the 'DIV' element, the variable 'count' will automatically increase 1</p>
</body>
</html>
Test and see ‹/›

Definition and Usage

ng-mousedown The directive is used to tell AngularJS what operation to perform when the mouse is pressed on the specified HTML element.

ng-mousedown The directive does not override the element's native onmousedown event, when the event is triggered,ng-mousedown Both the expression and the native onmousedown event will be executed.

The order in which the mouse clicks are executed:

  • Mousedown

  • Mouseup

  • Click

    Syntax

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

    All HTML elements support this directive.

    Parameter Value

    ValueDescription
    expressionExpression executed when the mouse is clicked.

    AngularJS Reference Manual