这是一个小提琴:http: //jsfiddle.net/NFQFp/
HTML:
<body ng-app ng-controller="bodyCtrl">
<input autofocus="autofocus" ng-model="fname"/>
<select ng-model="state">
<option ng-repeat="st in states" value="{{st}}" ng-selected="state == st">{{st}}</option>
</select>
{{state}}
</body>
JAVASCRIPT:
function bodyCtrl($scope) {
$scope.state = '';
$scope.states =["AK","AL","AR","AS","AZ","CA","CO","CT","DC","DE","FL","GA","GU","HI","IA","ID","IL","IN","KS","KY","LA","MA","MD","ME","MH","MI","MN","MO","MS","MT","NC","ND","NE","NH","NJ","NM","NV","NY","OH","OK","OR","PA","PR","PW","RI","SC","SD","TN","TX","UT","VA","VI","VT","WA","WI","WV","WY"]
}
如果您进入选择框并键入 A,然后键入 L,则模型将保留 AK 作为其值。如果您键入 A 然后 R 或 A 然后 Z,它工作正常。不知道这里发生了什么。似乎是任何结果集中的第二个不更新模型。AL、CO、DE... 等不按预期工作。这似乎只是打字时的问题,从列表中选择项目会按预期更新模型。如果您选择 AL,然后选择 AK,然后键入 AL,它将正常更新。这可能与浏览器未触发的事件有关吗?我正在使用 Chrome,它似乎会在您键入时更新模型,不像 firefox 在您模糊选择之前不会更新它。