3

The below code is detecting click in desktop but in mobile the touch event gets triggered when trying to scroll over the element,how to prevent this touch event and only detect tap events.I am not allowed to use ng-touch or ng-click. I have tried the below approaches but these dont seem to work.What changes need to be made in below code?

What's the best way to detect a 'touch screen' device using JavaScript?

onClick not working on mobile (touch)

What is the most reliable way to detect clicks (or touches) on both desktop and mobile devices?

(function() {
    'user strict';
    angular.module('myModule').directive('myDirective',function(){
    return{
    restrict:'A',
    scope:{
    id: '=myId',
    pm: '=myPm'
    },
    link:function(scope,element,attrs){
        element.on('click touchend',funtion(event){
        console.log("clicked");
        });
    }


    }:
    });

}());
Codemaster
  • 145
  • 2
  • 13

1 Answers1

0

use onclick="myFunction()" or use ng-click it'll work for sure in HTML-- ng-click="xyz(params)" like below shown::

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>ng-click in AngularJs</title>
    <script src="https://code.angularjs.org/1.4.1/angular.js"></script>
    <script>
        var app = angular.module('myApp', []);
        app.controller('ngClickCtrl', ["$scope", function ($scope) {
            $scope.domain = "stackoverflow.com";
            $scope.IsDisplay = false;
            $scope.clickMe = function (clicked) {
                    alert(" My Click function is called.");
                $scope.IsDisplay = clicked == true ? false : true;
            };
        }]);
    </script>
</head>
<body ng-app="myApp">
    <div ng-controller="ngClickCtrl">
        <div><h2>ng-click in AngularJs</h2> </div>
        <div>
            Domain name: <input type="text" ng-model="domain"> <button type="button" ng-click="clickMe(IsDisplay)">NG-CLICK</button>   
        </div>
        <div>
            <div ng-show="IsDisplay"> My Click function is called. <br /><h3 style="color:green;">testing ng-click events: {{domain}} </h3></div>
        </div>
    </div>
</body>
</html>