How to put a delay on AngularJS instant search?

前端 未结 13 1634
醉梦人生
醉梦人生 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条回答
  •  Happy的楠姐
    2020-11-30 17:28

    In Angular 1.3 I would do this:

    HTML:

    
    

    Controller:

    $scope.$watch('variableName', function(nVal, oVal) {
        if (nVal !== oVal) {
            myDebouncedFunction();
        }
    });
    

    Basically you're telling angular to run myDebouncedFunction(), when the the msg scope variable changes. The attribute ng-model-options="{debounce: 1000}" makes sure that msg can only update once a second.

提交回复
热议问题