我想在angularjs下拉列表中显示所选值。
<!DOCTYPE html>
<html>
<script
src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js">
</script>
<body>
<div><select class="form-control" size="30" style="
height:100px;width:100px" ng-model="value" ng-options="c.name for c
in customers track by c.id" ng-change="onChange">
<option value="" selected hidden />
</select></div>
</body>
</html>
通过以上方式,它不会突出显示所选值。如果我将ng-options
更改为ng-options="c.id as c.name for c in customers track by c.id"
。在值中,我看到id
而不是name
。
答案 0 :(得分:1)
您缺少ng-selected属性,添加属性ng-selected =&#34; value&#34;到你的选择元素。而且您不需要选项元素,并且还需要删除track by语句。
<select class="form-control" size="30" style=" height:100px;width:100px"
ng-model="value" ng-selected="value"
ng-options="c.id as c.name for c in customers">
</select>