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.
在锚标记中,我希望基于用户单击一次或两次的情况调用两个不同事件中的一个。但是,如果我实现了ng-click和ng-dblclick,这两个都将被激活。
Is there any way to route to the appropriate listener based on click count?
有什么方法可以基于单击计数路由到适当的侦听器吗?
1 个解决方案
#1
3
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;
您可以使用ng-click和$timeout的组合来计算函数执行的次数。代码可以是这样的;
<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)
}
#1
3
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;
您可以使用ng-click和$timeout的组合来计算函数执行的次数。代码可以是这样的;
<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)
}