मेरे पास एक तत्व है जो ng-mousedown
और ng-mouseup
पर फ़ंक्शन को सक्रिय करता है। हालांकि, यह टच स्क्रीन पर काम नहीं करता है, क्या ng-touchstart
और ng-touchend
जैसे कोई निर्देश है?एनजी-टचस्टार्ट और एनजी-टचचेन्ड Angularjs
उत्तर
इस के लिए एक मॉड्यूल है: https://docs.angularjs.org/api/ngTouch
लेकिन तुम भी घटनाओं के लिए अपने स्वयं के निर्देशों लिख सकते हैं:
<!doctype html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.js"></script>
</head>
<body ng-app="plunker">
<div ng-controller="MainCtrl">
<div my-touchstart="touchStart()" my-touchend="touchEnd()">
<span data-ng-hide="touched">Touch Me ;)</span>
<span data-ng-show="touched">M-m-m</span>
</div>
</div>
<script>
var app = angular.module('plunker', []);
app.controller('MainCtrl', ['$scope', function($scope) {
$scope.touched = false;
$scope.touchStart = function() {
$scope.touched = true;
}
$scope.touchEnd = function() {
$scope.touched = false;
}
}]).directive('myTouchstart', [function() {
return function(scope, element, attr) {
element.on('touchstart', function(event) {
scope.$apply(function() {
scope.$eval(attr.myTouchstart);
});
});
};
}]).directive('myTouchend', [function() {
return function(scope, element, attr) {
element.on('touchend', function(event) {
scope.$apply(function() {
scope.$eval(attr.myTouchend);
});
});
};
}]);
</script>
</body>
</html>
मैं उन ealier आज बना दिया है के बाद से मैं यह आवश्यक स्वयं:
- ngTouch (नीचे का एक संग्रह)
- ngTouchmove
- ngTouchstart
- ngTouchend
आशा है कि यह मदद करता है।
मैं ngTouchstart का उपयोग करना चाहता हूं, लेकिन दुर्भाग्य से यह eval() का उपयोग करता है, जो क्रोम ऐप में टूट जाएगा। –
इसके बजाय इसे '$ scope। $ Apply' का उपयोग करने के लिए अपडेट किया गया। –
धन्यवाद! क्या यह निर्देश से बाएं या दाएं स्थानांतरित करने का फैसला कर सकता है? – Martian2049
संस्करण जो हम $ parse() का उपयोग करते हैं, जो $ eval() आंतरिक रूप से उपयोग करता है। हम विशेष रूप से एक निर्देश का उपयोग करके mousedown और टचस्टार्ट घटनाओं को संभालना चाहते थे, लेकिन कोणीय तरीके से हम कोणीय शैली अभिव्यक्तियों को शामिल कर सकते हैं।
तो जैसा:
angular.module("ngStudentselect", []).directive('ngStudentselect', ['$parse', '$timeout', '$rootElement',
function($parse, $timeout, $rootElement) {
return function(scope, element, attr) {
var clickHandler = $parse(attr.ngStudentselect);
element.on('mousedown touchstart', function(event) {
scope.$apply(function() {
clickHandler(scope, {$event: event});
});
});
};
}]);
कोणीय के ngClick निर्देश का यह एक नीचे छीन संस्करण है।
- 1. module.run() और $ state.go() angularJS
- 2. AngularJs और Yii2
- 3. AngularJS और UI-Router
- 4. angularjs और express.js
- 5. AngularJS और पैटर्न/RegEx
- 6. AngularJS $ http और $ संसाधन
- 7. AngularJS और इंटरनेट एक्सप्लोरर
- 8. angularJS और C# webapi
- 9. AngularJS और Asp.Net MVC
- 10. Fabricjs और AngularJS
- 11. AngularJS और WebAPI
- 12. AngularJS, requJS और ngRoute
- 13. AngularJS $ संसाधन और हाइपरमीडिया
- 14. AngularJS: ngRransat और ngRepeat
- 15. angularjs और jquery
- 16. AngularJS और ReactJS
- 17. AngularJS और Number.NaN
- 18. MiniProfiler और AngularJS
- 19. जेसन और angularJs
- 20. Apache2 और संदर्भ पथ AngularJS
- 21. Animate.css और Angularjs ng-hide
- 22. AngularJS ng-if और scopes
- 23. angularJS element.on कॉलबैक और स्कोप। $
- 24. मार्ग रद्द करें और AngularJS
- 25. AngularJS और क्रॉस-डोमेन पोस्ट
- 26. AngularJS
- 27. AngularJS
- 28. AngularJS
- 29. angularjs
- 30. AngularJS
मैंने कल इस मॉड्यूल को स्थापित किया और मैंने इस पोस्ट को बाद में लिखा। मैं इन निर्देशों के साथ प्रयास करूंगा। – ciembor
कोणीय की एनजी टच लाइब्रेरी व्यक्तिगत स्पर्श और रिलीज घटनाओं के लिए बाध्यकारी का समर्थन नहीं करती है: http://stackoverflow.com/questions/19985097/can-angulars-ngtouch-library-be-used-to-detect-a-long-click- टच -होल्ड-रिलीज – Egg