How can I get the click count

2019-07-20 06:51发布

In an anchor tag I would like call one of two different events based on if the user clicked once or twice. However if I implement ng-click and ng-dblclick, both are activated.

Is there any way to route to the appropriate listener based on click count?

1条回答
在下西门庆
2楼-- · 2019-07-20 07:05

You can use a combination of ng-click and $timeout to count the number of times the function has been executed. the code could look like something like this;

 <a ng-click="clicked()" />


 $scope.clickCount = 0;
 var timeoutHandler = null;
 $scope.clicked = function()
 {
     if (timeoutHandler != null)
          $timeout.cancel( timeoutHandler );
     $scope.clickCount++;

     timeoutHandler = $timeout(function()
     {
         //now you know the number of clicks.
         //set the click count to zero for future clicks
         $scope.clickCount = 0;
     }, 500)
 }
查看更多
登录 后发表回答