我試圖使用ng選項創建下拉菜單,但是在編輯頁面不工作。如何在標籤和值相同的角度使用ng-options
js文件:
$scope.items = [
{name:"Angular"},
{name:"java script"},
{name:"Css3"},
{name:"Html5"},
];
$scope.name= "Css3";
HTML文件:
<div class="form-group">Name</label>
<select class="form-control" ng-model="name" ng-options="a.name for a in items track by a.name" placeholder="Select Item"></select>
</div>
其工作的罰款。 但還是選擇價值是這樣的:
name:{
name:"selectedValue"
}
,但我想是這樣的:
name:"selectedValue"
in $scope.selected after selected value from dropdown.
,我通過檢查元素比較@ Satpal的演示和我的輸出後,稱這blog
和得到這個:
我的輸出
<select class="form-control ng-pristine ng-valid" ng-model="name" ng-options="a.name as a.name for a in items" placeholder="Select Item">
<option value="0" selected="selected" label="Angular">Angular</option>
<option value="1" label="java script">java script</option>
<option value="2" selected="selected" label="Css3">Css3</option>
<option value="3">Html5</option>
</select>
Satpal的輸出:
<select class="form-control ng-pristine ng-valid" ng-model="name" ng-options="a.name as a.name for a in items" placeholder="Select Item">
<option value="0">Angular</option>
<option value="1">java script</option>
<option value="2" selected="selected">Css3</option>
<option value="3">Html5</option>
</select>
你可以創建一個小提琴和共享的鏈接? – Jan