下面是角預輸入我的HTML代碼:事先鍵入的內容獲取從URL的JSON值不工作數據
<div class="form-group">
<select name="" class="form-control" ng-model="city" ng-change="onChange(e)" id="city">
<option value="DELHI">DELHI</option>
<option value="BANGALORE">BANGALORE</option>
<option value="GOA">GOA</option>
<option value="KOLKATA">KOLKATA</option>
<option value="PUNJAB">PUNJAB</option>
</select>
</div>
<input type="search" name="" ng-model="bankName" typeahead='bank_name as bankName | filter:$viewValue | limitTo:8' id="input" class="form-control" value="" placeholder="Search" required="required" title="">
<table class="table table-hover">
<thead>
<tr>
<th>IFSC</th>
<th>BANK ID</th>
<th>BANK NAME</th>
<th>BRANCH</th>
<th>ADDRESS</th>
<th>CITY</th>
<th>DISTRICT</th>
<th>STATE</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="service in services">
<td>{{service.ifsc}}</td>
<td>{{service.bank_id}}</td>
<td>{{service.bank_name}}</td>
<td>{{service.branch}}</td>
<td>{{service.address}}</td>
<td>{{service.city}}</td>
<td>{{service.district}}</td>
<td>{{service.state}}</td>
</tr>
</tbody>
</table>
下面是JS文件:
var app = angular.module('bankBranch', ['ui.bootstrap'])
.controller('ServicesCtrl', ['$scope', '$http', function($scope, $http){
$scope.bankUrl = "https://someweb.com/api/bank_branches?offset=0&limit=50&city=";
$scope.city = 'BANGALORE';
var bankName = '$scope.bank_name';
var cities = '$scope.city';
$scope.getdata = function(){
$http.get($scope.bankUrl+$scope.city).then(function(response){
$scope.services = response.data;
});
}
$scope.onChange = function(e){
$scope.getdata();
}
$scope.getdata();
}]);
問題是我想要取分支名稱在輸入字段中,當我輸入下面的表格時,數據應該根據該數據進行過濾。 onChange函數適用於選擇框。 api網址的JSON格式如下:
[{
"ifsc": "asdads",
"bank_id": 110,
"bank_name": "abc bank",
"branch": "BANGALORE",
"address": "ewrwerewr",
"city": "BANGALORE",
"district": "BANGALORE URBAN",
"state": "KARNATAKA"
}]
任何想法如何修改此?卡住了。請幫幫我。
@zmbq你編輯我的代碼你知道我的代碼有什麼問題嗎? –
你是否使用了AngularJS UI Bootstrap的typeahead [這裏](https://angular-ui.github.io/bootstrap/#typeahead)?如果是這樣,你需要在搜索輸入標記中將'typeahead'更改爲'uib-typeahead' – segFault
@zmbq是的,我正在使用這一個 –