javascript - Want to make http get request only if text is typed in input field ANGULARJS -
the data coming local json file, want make http.get request when searchtext
(on keypress) typed in input field
<input type="text" class="form-control" ng-model="searchtext">
i show results in following 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>
in controller have far following:
$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); }
i'd use directive ng-change
.
<input type="text" class="form-control" ng-model="searchtext" ng-change="getdata()">
inside controller:
$scope.getdata = function(){ //implement $http logic. }
Comments
Post a Comment