Trying to capture all mobile events like touch and swipe, I have added event listeners at the document level:
document.addEventListener('tap', trackTouchActivity, false);
document.addEventListener('swipe', trackTouchActivity, false);
function trackTouchActivity(event) {
// handle any touch activity
}
While this setup works on the initial page of the angular app, it fails to function on subsequent pages or controllers.
My attempt to resolve this involved adding the code to $rootScope:
app.run(function($rootScope){
document.addEventListener('swipe', trackTouchActivity, false);
document.addEventListener('tap', trackTouchActivity, false);
function trackTouchActivity(event) {
$rootScope.$apply(function(){
// handle any touch activity
// set some variable to true
});
}
});
Being new to angular, I may be overlooking something. How can I ensure event listening functionality throughout the app?