我有一個select
其值是一個簡單的對象。選擇不顯示其默認值
顯示爲option
的內容是此對象的屬性,但值是對象本身。
我將此模型設置爲適當的對象,爲此select
設置默認值。
但select
不顯示任何選定的值,而模型設置正確。
這裏有3點不同的方法我試過:
Current value of representative.title : {{representative.title}} <br/><br />
<div class="form-group">
<select ng-model="representative.title"
ng-options="title.name for title in titles"
ng-disabled="$parent.isDisabled"
class="form-control">
</select>
</div>
<br />
<div class="form-group">
<select ng-model="representative.title"
class="form-control">
<option ng-repeat="title in titles"
value="{{title}}">
{{title.name}}
</option>
</select>
</div>
<br />
<div class="form-group">
<select ng-model="representative.title"
ng-options="title as title.name for title in titles"
ng-disabled="$parent.isDisabled"
class="form-control">
</select>
</div>
而且在我的控制器:
$scope.titles = [{"name": "Monsieur"},{"name": "Madame"}];
$scope.representative = {"title": {"name": "Monsieur"}, "otherField": "otherValue"};
爲什麼不是我的選擇顯示的默認值?
我該如何解決?
(順便說一句,我使用的角度1.2.28)
___'{}!== {}'___ – Rayon
可能的答案在這裏? http://stackoverflow.com/questions/29407513/angularjs-dropdown-not-showing-selected-value – Simo
可能'ng選項'與'標籤爲'可能會幫助你... – Rayon