如何选择states.address并希望显示state.address但是ng-model selPcode会显示state.postcode?
这是一个有效的jsfiddle http://jsfiddle.net/qbp2gqep/。
这是json数组对象:
$ scope.states = [{postcode:'B1',地址:'Bull ring'},{postcode:'M1',地址:'Manchester'}];
以下是html代码段:postcode
<input type="text" ng-model="selPcode" /> typeahead
<input type="text" ng-model="selPcode" typeahead="state.postcode as state.address for state in states | filter:$viewValue" typeahead-editable="false" />
我可以获得state.address或state.postcode,但不是我想要的方式,即显示state.address,但内部模型应该有state.postcode。
感谢任何帮助。
TIA。
答案 0 :(得分:1)
您应该使用ui-bootstrap typeahead,如下所示
<input type="text" ng-model="selected" placeholder="Type your Address"
uib-typeahead="state as state.address for state in states | filter:{address:$viewValue}"
class="form-control" typeahead-show-hint="true" typeahead-min-length="0">
<强> LIVE DEMO 强>