How to put a delay on AngularJS instant search?

前端 未结 13 1680
醉梦人生
醉梦人生 2020-11-30 16:55

I have a performance issue that I can\'t seem to address. I have an instant search but it\'s somewhat laggy, since it starts searching on each keyup().

13条回答
  •  忘掉有多难
    2020-11-30 17:32

    I believe that the best way to solve this problem is by using Ben Alman's plugin jQuery throttle / debounce. In my opinion there is no need to delay the events of every single field in your form.

    Just wrap your $scope.$watch handling function in $.debounce like this:

    $scope.$watch("searchText", $.debounce(1000, function() {
        console.log($scope.searchText);
    }), true);
    

提交回复
热议问题