在 angularjs 的下拉列表中突出显示所选值
Highlight selected value in drop down in angularjs
我想在 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>
通过上述方式,它不会突出显示所选 value.If 我将 ng-options
更改为 ng-options="c.id as c.name for c in customers track by c.id"
。在我看到的值中 id
而不是 name
.
您缺少 ng-selected 属性,请将属性 ng-selected="value" 添加到您的 select 元素。而且不需要option元素,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>
我想在 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>
通过上述方式,它不会突出显示所选 value.If 我将 ng-options
更改为 ng-options="c.id as c.name for c in customers track by c.id"
。在我看到的值中 id
而不是 name
.
您缺少 ng-selected 属性,请将属性 ng-selected="value" 添加到您的 select 元素。而且不需要option元素,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>