点击事件在带有angularjs的iPad中无法正常工作 [英] click event not working properly in iPad with angularjs
问题描述
我为属性globalEvents创建了angularjs指令并添加到body元素中。请找到以下代码:
I created angularjs directive for attribute globalEvents and added to body element. Please find below code:
<body globalEvents>
<div id="container" ng-controller="appController">
Angularjs代码:
Angularjs code :
angularApp.directive('globalEvents', [function() {
return {
restrict:"A",
replace:true,
link:function(scope,elm,attr) {
elm.on('click', function (e) {
// not working in iPad
}
}
}
}
以上点击事件在iPad中不起作用,除非我添加ng-click属性到容器div (id =container)
Above click event not working in iPad unless and until I add ng-click attribute to container div (id="container")
<div ng-click="" id="container" ng-controller="appController">
I不明白这背后的原因。但这不是解决这个问题的方法。请帮助我
I don't understand reason behind this. But this is not solution for this issue. Please help me
我使用的是AngularJS v1.2.15
I am using AngularJS v1.2.15
推荐答案
我想你应该使用 angular.element()
angular.element(elm).on('click touchstart', function (e) {
//^^^^^^^^^^^^^^^^^^-----------^^^^^^^^^^
当你将jqLite的事件绑定到原始DOM节点 elm
时,你应该用 angular.element
创建一个jquery对象来附加jqlite事件。
As you are binding a jqLite's event to a raw DOM node elm
, instead you should wrap it with angular.element
to create a jquery object to attach a jqlite event on it.
这篇关于点击事件在带有angularjs的iPad中无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!