Angularjs Debounce在IE9中不起作用
我的网站目前使用AngularJS v1.2.8版的去盎司指令。在FF和Chrome中,去盎司效果良好,但在IE9中不会出现延迟。我有一个严格的要求,以支持IE9,我不能升级到一个新版本的Angular。此代码的哪一部分与IE9不兼容?或者,如果IE9中有一个已知有效的去盎司指令,我们将不胜感激 当前的去盎司指令:Angularjs Debounce在IE9中不起作用,angularjs,internet-explorer-9,debouncing,Angularjs,Internet Explorer 9,Debouncing,我的网站目前使用AngularJS v1.2.8版的去盎司指令。在FF和Chrome中,去盎司效果良好,但在IE9中不会出现延迟。我有一个严格的要求,以支持IE9,我不能升级到一个新版本的Angular。此代码的哪一部分与IE9不兼容?或者,如果IE9中有一个已知有效的去盎司指令,我们将不胜感激 当前的去盎司指令: angular.module('stuff.debounce', []).directive('ngDebounce', function($timeout) { ret
angular.module('stuff.debounce', []).directive('ngDebounce', function($timeout) {
return {
restrive: 'A',
require: 'ngModel',
priority: 99,
link: function(scope, elm, attr, ngModelCtrl) {
if(attr.type === 'radio' || attr.type === 'checkbox') return;
elm.unbind('input');
var debounce;
elm.bind('input', function() {
$timeout.cancel(debounce);
debounce = $timeout( function () {
scope.$apply(function() {
ngModelCtrl.$setViewValue(elm.val());
});
}, attr.ngDebounce || 1000);
});
elm.bind('blur', function() {
scope.$apply(function() {
ngModelCtrl.$setViewValue(elm.val());
});
});
}
};
});
尝试了一些其他的去Bounce API,但都不起作用,所以我编写了一个在IE9中用于去Bounce的javascript方法
var deb = undefined;
$scope.someMethod = function() {
if(deb !== undefined)
$timeout.cancel(deb);
deb = $timeout( function() {
//do stuff that you want debounced
deb = undefined;
}, 1500); //1500 is the debounce delay in ms
};
抱歉,如果这太乱了,我必须从手机上写下它。好吧,在github的这个脚本后面,据说它与IE9不兼容。你最好另找一个@Apédémak 1.2.8支持IE8及以上版本@KevinB我不是说棱角分明的。。。。我说的是在github上找到的这个脚本。你可能想澄清你的问题,它一字不差地说:“我使用的是AngularJS1.2.8