ngTouch event example using angularjs-ngtouch directive

ngTouch event example using angularjs-ngtouch directive

Installation

A angularjs simple add bew module to add directives for touch mobile,iphone,tablet or more devices.

[php]
“//ajax.googleapis.com/ajax/libs/angularjs/X.Y.Z/angular-touch.js”


[/php]

A angularjs module to simple add directives for some touch devices.

How to use it

You must here app’s include the ngTouch directive dependency on your module add angular module:

[php]
var app = angular.module(“infinityApp”, [“ngTouch”]);

[/php]

Example

index.html

[php]

ngtouch directive angularjs example jsfiddle

Touch device or click device me
Touch device or click device me
Touch device or click device me


Display : {{comment.join(‘ | ‘)}}

[/php]

READ :  AngularJs ng click and ng touch mobile device

index.js

[php]
var app = angular.module(‘test’, []);

app.directive(‘onTouch’, function() {
return {
restrict: ‘A’,
link: function(scope, elm, attrs) {
var ontouchFn = scope.$eval(attrs.onTouch);
elm.bind(‘touchstart’, function(evt) {
scope.$apply(function() {
ontouchFn.call(scope, evt.which);
});
});
elm.bind(‘click’, function(evt){
scope.$apply(function() {
ontouchFn.call(scope, evt.which);
});
});
}
};
});

app.controller(‘liveCtrl’, function($scope) {
$scope.comment = [];
$scope.livetouch = function(item) {
(item) ? item = 1 : null
for (var i =0 ; i< item ; i++) { $scope.comment.push("Fire"); } }; }); [/php]

style.css

[php]
.btn {
display: block;
border: 2px solid;
height: 150px;
width: 150px;
float: right;
margin: 15px;
padding: 10px;
}
[/php]

Example

Leave a Comment