我有一个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