来自ngTouch ngClick documentation :
A more powerful replacement for the default ngClick designed to be used on touchscreen devices. Most mobile browsers wait about 300ms after a tap-and-release before sending the click event. This version handles them immediately, and then prevents the following click event from propagating.
这会造成不一致的行为,因为在计算机上,点击事件继续冒泡/传播,但在移动设备上,它停止了。这意味着任何在 dom 中更高层的监听元素点击的指令都会失败。对我来说似乎是一个错误,但我一定不是第一个必须解决这个问题的人。
如果您查看 ngTouch code, the problem stems from line 453
element.triggerHandler('click', [event]);
angular.element
delegates to Angular's built-in subset of jQuery, called "jQuery lite" or "jqLite."
jqLite 可以访问 jQuery 的 triggerHandler
,但不能访问 trigger
。
The .triggerHandler() method behaves similarly to .trigger(), with the following exceptions:
- Events triggered with .triggerHandler() do not bubble up the DOM hierarchy; if they are not handled by the target element directly, they do nothing.
因此 Angular 人员需要向 jqLite 添加 trigger
支持并将该行更改为 trigger
以使其正常工作。
与此同时,我该如何解决这个问题?有没有办法在自定义指令中使用 ngClick?
笑声奖励:Comment from the ngTouch source code
// This is an ugly, terrible hack!
// Yeah, tell me about it.
最佳答案
我已经用
替换了第 453 行element[0].dispatchEvent(new MouseEvent('click', event));
目前一切正常。不确定 new MouseEvent()
的浏览器兼容性如何,所以请随时发表评论。
关于javascript - ngTouch ngClick 不冒泡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26685498/