-1

私のウェブサイトは現在、AngularJS v1.2.8 で debounce ディレクティブを使用しています。FF と Chrome ではデバウンスは問題ありませんが、IE9 では遅延は発生しません。IE9 をサポートするという厳格な要件があり、新しいバージョンの Angular にアップグレードできません。このコードのどの部分が IE9 と互換性がありませんか? または、IE9 で動作することが既に知られているデバウンス ディレクティブがある場合は、大いに感謝します。

現在のデバウンス ディレクティブ:

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());
                });
            });
        }
    };
});
4

1 に答える 1

0

他のデバウンス API をいくつか試しましたが、どれも機能しなかったため、デバウンスのために IE9 で動作する小さな 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
};

スマホから書いたので汚くてすみません。

于 2015-07-29T17:03:08.170 に答える