2013-09-16 57 views
1

這裏選擇使用類型的值是一個小提琴:http://jsfiddle.net/NFQFp/與角度可能的錯誤在Chrome

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"] 
} 

如果標籤爲選擇框和類型那麼L,模型仍然以AK作爲其值。如果你輸入A然後R或A然後Z,它工作正常。不知道這裏發生了什麼。似乎是任何結果集的第二個不更新模型。 AL,CO,DE等沒有按預期工作。這隻會在打字時出現問題,從列表中選擇項目會按預期更新模型。如果你選擇AL,然後AK,然後輸入AL,它會更新正常。這可能與不從瀏覽器觸發的事件有關嗎?我使用的是Chrome,它似乎在鍵入時更新模型,與firefox不同,直到您模糊選擇才更新它。

回答

2

請勿使用ng-repeat with select;使用:

<select ng-model="state" ng-options="st for st in states"> 

參見docs

現在按A L去AL(你必須快速按下它們)。小提琴:http://jsfiddle.net/XyaR9/

+0

這小提琴仍然似乎對我有同樣的問題 – chris

+0

另外,問題不是它沒有選擇正確的選擇框中,問題是它沒有更新模型屬性 – chris

+0

在兩種情況下離開選擇時模型都會更新......我認爲這很正常。在選擇集中的情況下,您按上/下時也會發生相同的行爲。不過,你應該使用'ng-options'。 –