在搜索框中使用 ng-change

Using ng-change in search box

要求:

 $scope.viewAccount = function(){
      var json = {

  "json": {
    "request": {
      "servicetype": "60",
      "functiontype": "1014",
           "data": {
        "shortname": $scope.model.selectShortName,
        "groupzname": $scope.model.selectGname,
        "city": $scope.model.selectCity,
        "state": $scope.model.selectState,
        "country": $scope.model.selectCountry,
        "groupzcode": $scope.model.selectGcode,
         "activationstatus": true,
        "details": false,
        "sortbasedon": $scope.groupzname,
        "orderby": "desc",
        "limit":10,
           }

    }
  }
};

              UserService.viewListAccount(json).then(function(response) {

  console.log(JSON.stringify(json));
                 if (response.json.response.statuscode == 0 && response.json.response.statusmessage == 'Success')
                        {
                   $scope.tableData = response.json.response.data;
                  console.log($scope.tableData);
                        }
                  else{
                  alert(response.json.response.statusmessage);

                  }

            }); 
        };

以上功能是将所有数据显示到 table.I 在 groupzname、shortname 中有一个搜索框,我使用 ng-change 并调用了一个新函数 changeviewAccount() 删除请求中的偏移量。但是我遇到的问题是即使我在搜索框中输入一个字母,每次都会调用该函数。我是 AngularjS 的新手。

您可以使用 ng-blur 而不是 ng-change ,它告诉 AngularJS 当输入框失去焦点时该怎么做。

  <input ng-blur="changeviewAccount()" type="text" class="form-control"  placeholder="Title">