ngClick And ngDblclick Directives In AngularJS

Introduction

AngularJS provides many built-in directives. In this article we will discuss about ngClick and ngDbclick directives.

ngClick

This directive allows us to define custom behavior on element click event. This directive has highest priority. In expression, event object is accessible as $event.

Syntax

<ANY ELEMENT ng-click="expression">
...
</ANY ELEMENT>


Example

HTML

  1. <h4>ngClick Example</h4>  
  2. <div ng-controller="HomeController">  
  3.     <button ng-click="click()"> Click Here </button>  
  4. </div>  
Controller
  1. var app = angular.module("app", []);  
  2. app.controller("HomeController", function ($scope)  
  3. {  
  4.     $scope.click = function ()  
  5.     {  
  6.         alert('Perform click event');  
  7.     }  
  8. });  
Output
ngClick

ngDblclick

This directive allows us to define custom behavior on element double click event. This directive has highest priority. In expression, event object is accessible as $event.

Syntax

<ANY ELEMENT ng- dblclick ="expression">
...
</ANY ELEMENT>


Example

HTML
  1. <h4>ngDblclick Example</h4>  
  2. <div ng-controller="HomeController">  
  3.     <button ng-dblclick="dblclick()"> Click Here </button>  
  4. </div>  
Controller
  1. var app = angular.module("app", []);  
  2. app.controller("HomeController", function ($scope)  
  3. {  
  4.     $scope.dblclick = function ()  
  5.     {  
  6.         alert('Perform double click event');  
  7.     }  
  8. });  
Output

Output

Summary

The ngClick and ngDblclick are important directives and to perform it double click and blur event in AngularJS. This article will help you to learn all of them.