大佬教程收集整理的这篇文章主要介绍了angularjs – 角度ng变化延迟,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
输入
<input ng-model="xyz" ng-change="FilterByName()" />
重复
<div ng-repeat"foo in bar"> <p>{{foo.bar}}</p> </div>
过滤功能
$scope.FilterByName = function () { //Filtering stuff Here });
谢谢
由于AngularJS 1.3,你可以利用debounce属性ngModelOptions
提供实现非常容易,而不使用$ timeout。这里有一个例子:
HTML:
<div ng-app='app' ng-controller='Ctrl'> <input type='text' placeholder='Type a name..' ng-model='vm.name' ng-model-options='{ debounce: 1000 }' ng-change='vm.greet()' /> <p ng-bind='vm.greeTing'></p> </div>
JS:
angular.module('app',[]) .controller('Ctrl',[ '$scope','$log',function($scope,$log){ var vm = $scope.vm = {}; vm.name = ''; vm.greeTing = ''; vm.greet = function greet(){ vm.greeTing = vm.name ? 'Hey,' + vm.name + '!' : ''; $log.info(vm.greeTing); }; } ]);
– 要么 –
之前的AngularJS 1.3
你必须使用$ timeout添加一个延迟,并且可能使用$ timeout.cancel(prevIoUstimeout),你可以取消任何先前的超时,并运行新的超时(有助于防止过滤被执行多次在一个时间间隔)
这里是一个例子:
app.controller('MainCtrl',$timeout) { var _timeout; //... //... $scope.FilterByName = function() { if(_timeout) { // if there is already a timeout in process cancel it $timeout.cancel(_timeout); } _timeout = $timeout(function() { console.log('filtering'); _timeout = null; },500); } });
以上是大佬教程为你收集整理的angularjs – 角度ng变化延迟全部内容,希望文章能够帮你解决angularjs – 角度ng变化延迟所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。