在 anchor 标记中,我想根据用户是否单击一次或两次来调用两个不同事件之一。但是,如果我实现 ng-click
和 ng-dblclick
,两者都会被激活。
有没有办法根据点击次数路由到适当的监听器?
最佳答案
您可以使用 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)
}
关于angularjs - 如何获取点击次数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27557859/