【发布时间】:2016-09-24 23:54:10
【问题描述】:
脚本不仅会从我的 JSON 中返回我需要的值。我需要来自 JSON 的名称
当我在输入字段中输入一些值时,以下内容会生成自动建议。
参考:http://plnkr.co/edit/08vi4ncjLrWfUBjWrZKS?p=preview
但是,这不会在我的代码中返回任何 JSON 值:
<script>
var app = angular.module('myApp', ['ui.bootstrap']);
app.controller('myController', function($scope, $http){
$scope.getAirport = function(inp){
return $http.get('https://raw.githubusercontent.com/vedvasa/airports/master/airports.json', {
params: {
name : inp,
sensor : false
}
}).then(function(res){
var names = [];
angular.forEach(response.data.records, function(item){
names.push(item.addedNames);
});
return names;
});
};
$scope.on_item_selected=function($item, $model, $label)
{
$scope.selected_item = $item;
}
});
</script>
<div ng-app="myApp" ng-controller="myController">
<form>
<input type="text" class="form-control" id="source" placeholder="Enter Airport Code or City Name" ng-model="asyncSelected" typeahead="name for name in getAirports($viewValue)" typeahead-loading="loadingAirports" typeahead-on-select="on_item_selected($item, $model, $label)">
</form>
</div>
【问题讨论】: