Javascript 在angularjs上的keyup事件中,如何在两秒钟后发送请求?

Javascript 在angularjs上的keyup事件中,如何在两秒钟后发送请求?,javascript,angularjs,Javascript,Angularjs,当用户停止在angularjs中键入时,有没有办法在两秒钟后将请求发送到服务器。类似于去毛刺。换句话说,如果用户键入“abc”并停止等待两秒钟,然后点击服务器 当前每当我键入它请求服务器的任何字符时 这是我的密码 你好{{name}} 使用设置超时功能 var app = angular.module('plunker', []); app.controller('MainCtrl', function($scope,$http) { $scope.name = 'World'; $s

当用户停止在angularjs中键入时,有没有办法在两秒钟后将请求发送到服务器。类似于去毛刺。换句话说,如果用户键入“abc”并停止等待两秒钟,然后点击服务器

当前每当我键入它请求服务器的任何字符时 这是我的密码


你好{{name}}


使用设置超时功能

var app = angular.module('plunker', []);

app.controller('MainCtrl', function($scope,$http) {
$scope.name = 'World';


$scope.keyupevt = function(){

  setTimeout(function(){

     $http.get("data.json").then(function(response) 
     {
       console.log(response)
     }
     )}, 2000);//delay parameter of 2 seconds

  }
});

可以使用
ng model options
指令解除输入的抖动:

  <body ng-controller="MainCtrl">
    <p>Hello {{name}}!</p>
    <input type="text"
           ng-model="name"
           ng-model-options="{ debounce: 2000 }"    
           ng-change="keyupevt()" />
  </body>

你好{{name}}

有关详细信息,请参阅


可以使用
ng model options
指令解除输入的抖动。看见
var app = angular.module('plunker', []);

app.controller('MainCtrl', function($scope,$http) {
$scope.name = 'World';


$scope.keyupevt = function(){

  setTimeout(function(){

     $http.get("data.json").then(function(response) 
     {
       console.log(response)
     }
     )}, 2000);//delay parameter of 2 seconds

  }
});
  <body ng-controller="MainCtrl">
    <p>Hello {{name}}!</p>
    <input type="text"
           ng-model="name"
           ng-model-options="{ debounce: 2000 }"    
           ng-change="keyupevt()" />
  </body>