Call Function with Delay When Textbox Changes in AngularJS

后端 未结 3 881
没有蜡笔的小新
没有蜡笔的小新 2021-02-01 05:08

Can\'t seem to google up an example of how this is done.

I have successfully created a textbox that calls a function every time it changes. What I would like to do is o

3条回答
  •  一整个雨季
    2021-02-01 05:21

    For angular approach can inject $timeout in controller as dependency and use $watch on scope variable you've assigned in ng-model.

    var timer=false;
    $scope.ModelName='foo';
    $scope.$watch('ModelName', function(){
      if(timer){
          $timeout.cancel(timer)
      }  
      timer= $timeout(function(){
          /* run code*/
       },delay)
    });
    

提交回复
热议问题