我正在尝试使用http://angular-ui.github.io/bootstrap/在Angular中实现类型提示(Typeahead),其中类型提示字段显示完整地址,但是一旦点击,另一个字段将仅填充该地址的邮政编码。我正在尝试使用ng-change或ng-click进行此操作,但没有成功。
angular.module('myApp', ['ui.bootstrap'])
.controller("mainCtrl", function ($scope) {
$scope.selected = '';
$scope.states = [{postcode:'B1',address:'Bull ring'},{postcode:'M1',address:'Manchester'}];
$scope.setPcode = function(site) {
$scope.selPcode = site.postcode;
};
});
<div class="container">
<div ng-controller="mainCtrl" class="row-fluid">
<form class="row-fluid">
<div class="container-fluid">
postcode <input type="text" ng-model="selPcode" />
typeahead <input type="text" ng-change="setPcode(site)" ng-model="selected" typeahead="state.address for state in states | filter:$viewValue" />
</div>
</form>
</div>
</div>
有什么想法吗?