我正在尝试使用http://angular-ui.github.io/bootstrap/在 Angular 中实现 typeahead ,其中 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>
有任何想法吗?