ng-click 在移动或平板设备上触发 [英] ng-click on firing on mobile or tablet devices
问题描述
在页面加载时,我有一个控制器调用服务,然后将返回的数据绑定到一些 $scope.objects:
On page load i have a controller that calls a service and then binds the returned data to some $scope.objects:
app.controller("MainController", function($scope, $http, serviceGetData) {
serviceGetData.getData(function(data) {
$scope.LoginCount = data.LoginCount;
$scope.ProductInfo = data.ProductInfo;
$scope.ProfileInfo = data.ProfileInfo;
// Delayed binding
$scope.OrderHistory = { History: [] };
}
$scope.populateModel = function(model, values) {
var isArray = $.isArray(values);
$.each(values, function(key, value) {
if (isArray) {
key = this.key;
value = this.value;
}
if (model[key] !== value) {
model[key] = value;
}
});
};
}
在我的 HTML 中,我尝试通过以下方式绑定 $scope.OrderHistory:
And in my HTML, i try to bind $scope.OrderHistory by:
<h1><a href="#" ng-click="populateModel(OrderHistory , { History: OrderEntries })" >View order details</a></h1>
这在笔记本电脑/台式机上观看时很好,但在平板电脑和移动设备上不起作用,例如iphone/ipad
This is fine when viewing on laptops/desktops, but not working in tablet and mobile devices e.g. iphone/ipad
推荐答案
尝试添加 ngTouch.来自文档:
设计用于触摸屏设备的默认 ngClick
的更强大替代品.大多数移动浏览器在点击和释放之后等待大约 300 毫秒,然后再发送点击事件.此版本会立即处理它们,然后阻止以下点击事件传播.
A more powerful replacement for the default
ngClick
designed to be used on touchscreen devices. Most mobile browsers wait about 300ms after a tap-and-release before sending the click event. This version handles them immediately, and then prevents the following click event from propagating.
需要安装 ngTouch
模块.
Requires the ngTouch
module to be installed.
这篇关于ng-click 在移动或平板设备上触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!