只想在输入字段中输入文本时才发出 http get 请求 ANGULARJS

Want to make http get request only if text is typed in input field ANGULARJS

数据来自本地 json 文件,但我希望它仅在输入字段中键入 searchText(按键)时发出 http.get 请求

  <input type="text" class="form-control" ng-model="searchText">

我会在下面展示结果table:

<table ng-if="searchText" class="searchResults table table-bordered table-hover table-responsive"> 
  <tr>
    <th>DLL ID</th>
    <th>KVK Nummer</th>
    <th>Company Name</th>
  </tr>

  <tr ng-repeat="data in getData | filter: customFilter">
   <td>{{data.Id}}</td>
   <td>{{data.stTax_ID_VAT_Number}}</td>
   <td>{{data.AccountName}}</td>
</table>

到目前为止,在我的控制器中:

    $scope.searchText = undefined;

    if($scope.searchText){
    $http.get('data/json_sample/DV_IC_01.json')
            .success(function(data){
                $scope.allData = data;
                $scope.getData = $scope.allData.d.results;
            });
}
    $scope.customFilter = function(row){
        if (!$scope.searchText){
                return true;
            }

        return (row.stTax_ID_VAT_Number.indexOf($scope.searchText) !== -1) || (row.AccountName.toLowerCase().indexOf($scope.searchText.toLowerCase()) !== -1);
    }

我会使用指令 ng-change

<input type="text" class="form-control" ng-model="searchText" ng-change="getData()">

在你的控制器中:

$scope.getData = function(){
  //implement your $http logic.
}