Angularjs的debounce正在清除我的无线电输入
Angularjs debounce is clearing my radio input
我有以下单选按钮组:
<input type="radio" name="GROUP" ng-model="data1" id="for1" value="value" ng-change="formSubmit()" ng-model-options="{debounce: 3000}">
<input type="radio" name="GROUP" ng-model="data2" id="for2" value="value" ng-change="formSubmit()" ng-model-options="{debounce: 3000}">
如您所见,在ng-click
上,我让它运行一个特定的函数,但也让debounce
只在3秒超时时发生。
当我有ng-model-options="{debounce: 3000}"
存在时,通常,我的无线电组将取消选中-这意味着组中没有输入将被选中。
当我删除debounce时,这个问题就不会发生了。
有人知道我怎么能解决这个问题吗?
根据上面的评论,假设你想保留第一次点击,并在3秒延迟内忽略后续的点击,我建议:
<input type="radio" ng-change="doItLater();" value="X">
(同时,在指令中:
)scope.doItLater = function() {
if (scope.timeoutwatcher !== undefined) {return;}
scope.timeoutwatcher = $timeout(function() {
// do it
delete scope.timeoutwatcher;
},3000);
}
或者,如果您希望在超时时间内让稍后的单击覆盖先前的单击,
scope.doItLater = function() {
$timeout.cancel(scope.timeoutwatcher);
scope.timeoutwatcher = $timeout(function() {
// do it
},3000);
}
这样做可能会有帮助
angular
.module('app', [])
.controller('example', ['$scope', function($scope) {
$scope.user = {};
$scope.$watch('user.gender', $scope.callback);
$scope.callback = function() {
alert($scope.user);
}
}]);
在HTML中输入
<form ng-app="app" ng-controller="example">
<input name="jim" type="radio" ng-model="user.gender" value="male" ng-model-options="{debounce: 3000}" />male
<input name="jim" type="radio" ng-model="user.gender" value="female" ng-model-options="{debounce: 3000}" />female
<br />
<pre>form = {{user | json}}</pre>
相关文章:
- 为什么不't Javascript对我的输入值进行了一些重新检查
- 可以't让我的if语句处理js中的html表单输入
- 我的单元测试选项是什么
- 将输入字段中的文本提交到我的数据库,同时将其添加到我的列表中
- 我的职位回报太快了,如何做出承诺
- 我的jQuery插件参数没有正确启动,遇到了问题
- 如何识别我的网站中的慢速设备
- 如何将JSON数据导入我的ejs模板
- JQuery添加元素需要在我的js之前再次添加JQuery脚本
- 知道为什么我的旋转木马不会自动更改图片吗
- 我的模板未被解析
- 无法将数据从firebase获取到我的html页面
- 角度图表;t显示在我的页面中
- 为什么我的无线电输入值是 NaN
- 我的 JavaScript 无法正确检查表单的无线电输入
- 我应该如何根据所选的无线电输入重新组织查询的控制流
- 在我的表单中,我检查了输入无线电和图像更改,但我填充输入文本和图像更改回来
- 我有一个表单和一个按钮来添加它的副本.我希望重复的无线电输入具有变量名
- 最终显示不正确的无线电值.我不知道为什么
- Angularjs的debounce正在清除我的无线电输入