How can I get the click count

自闭症网瘾萝莉.ら 提交于 2019-12-11 01:51:57

问题


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:


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)
 }


来源:https://stackoverflow.com/questions/27557859/how-can-i-get-the-click-count

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!