简体   繁体   English

click事件在iPad中使用angularjs无法正常工作

[英]click event not working properly in iPad with angularjs

I created angularjs directive for attribute globalEvents and added to body element. 我为属性globalEvents创建了angularjs指令,并将其添加到主体元素中。 Please find below code: 请找到以下代码:

<body globalEvents>
<div id="container" ng-controller="appController"> 

Angularjs code : Angularjs代码:

    angularApp.directive('globalEvents', [function() {
        return {
            restrict:"A",
            replace:true,
            link:function(scope,elm,attr) {
                elm.on('click', function (e) {
                   // not working in iPad
                }
            }
       }
   }

Above click event not working in iPad unless and until I add ng-click attribute to container div (id="container") 除非并且直到我将ng-click属性添加到容器div (id="container")以上单击事件才能在iPad中工作

<div ng-click="" id="container" ng-controller="appController"> 

I don't understand reason behind this. 我不明白这背后的原因。 But this is not solution for this issue. 但这不是解决此问题的方法。 Please help me 请帮我

I am using AngularJS v1.2.15 我正在使用AngularJS v1.2.15

I guess you should use angular.element() 我猜你应该使用angular.element()

 angular.element(elm).on('click touchstart', function (e) {
 //^^^^^^^^^^^^^^^^^^-----------^^^^^^^^^^

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. 当您将jqLit​​e的事件绑定到原始DOM节点elm ,您应该使用angular.element包裹它,以创建一个jquery对象以在其上附加jqlite事件。

Docs for angular.element() Angular.element()的文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM