How to put a delay on AngularJS instant search?

前端 未结 13 1679
醉梦人生
醉梦人生 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:47

    Why does everyone wants to use watch? You could also use a function:

    var tempArticleSearchTerm;
    $scope.lookupArticle = function (val) {
        tempArticleSearchTerm = val;
    
        $timeout(function () {
            if (val == tempArticleSearchTerm) {
                //function you want to execute after 250ms, if the value as changed
    
            }
        }, 250);
    }; 
    

提交回复
热议问题