2014-02-18 51 views
0

我試圖在當前的項目中做過幾次,但不知何故,現在它不會工作。Angular JS ng-options不取值

我有對象的數組,在它:

$scope.teacherList = [{"id":1,"firstName":"Dave","lastName":"Squarepants"},{"id":2,"firstName":"Patrick","lastName":"Star"}] 

現在我就與NG-選項的選擇框:

<select name="teacher" ng-model="crudTeacher.teacher.id" ng-options="teacher.id as teacher.firstName + ' ' + teacher.lastName for teacher in teacherList" required></select> 

但是,當我看值,北京時間只是0和1,即使ID是1和2.

角度以某種方式沒有把teacher.id當作正確的部分。

我錯過了什麼嗎?

回答

1

根據我的樣本,它顯示正確的值:

http://jsbin.com/quhigumu/2/edit

enter image description here

enter image description here

+0

但看看屬性的值: <期權價值= 「?」選擇=「selected」>

+1

@DavidFariña你是說要檢查元素嗎?如果是這樣,不要。 NG在其他地方照顧值。 (所以你不會在dom中看到它)。 –

+0

Didnt非常知道thx! –