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 code :
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")
<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
I guess you should use 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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.