2016-01-04 69 views
0

我有以下代碼。ng選項sected屬性不起作用

<div class="form-group"> 
    <label class="col-lg-4 control-label" for="gcAttribute">GC</label> 
    <div class="col-lg-8"> 
     <select class="form-control" id="gcAttribute" ng-selected="selectedAttribute.GC" ng-model="selectedAttribute.GC" ng-options="item as item.ColumnName for item in tableColumns | filter:{TableName:'GC'}"></select> 
     <textarea>{{selectedAttribute.GC|json}}</textarea> 
    </div> 
</div> 

我的選項已填充,但沒有選擇。我相信我正在做一些不容易理解的事情。

我有一個對象稱爲selectedAttribute,我想編輯,它有很多特性GCPE的,SL

GCPESL是某種像下面陣列的一個對象tableColumns

{{TableName:"GC", ColumnName="IdeaName" ..............} 

{TableName:"PE", ColumnName="PresenterId" ............} 

{TableName:"SL", ColumnName="VenueId" ..............}} 

同時編輯我需要一個組合框與對象上的選擇選項我可以得到選項位罰款,但選定的選項沒有被選中。

回答

0

下解決了我的問題與NG選項

<div class="form-group"> 
<label class="col-lg-4 control-label" for="gcAttribute">GC</label> 
<div class="col-lg-8"> 
    <select class="form-control" id="gcAttribute" ng-selected="selectedAttribute.GC" ng-model="selectedAttribute.GC" ng-options="item.ColumnName as item.ColumnName for item in tableColumns | filter:{TableName:'GC'}"></select> 
    <textarea>{{selectedAttribute.GC|json}}</textarea> 
</div> 
</div> 

密鑰字符串是

item.ColumnName as item.ColumnName 

而且我可以看到這樣的結果。

<option value="string:IdeaName" label="IdeaName">IdeaName</option> 
<option value="string:IdeaSector" label="IdeaSector">IdeaSector</option> 

希望可以幫助一些一

和選擇也適用,由於JB的所有建議。

0

select directive上沒有ng-selected屬性。

要選擇其中一個選項,您不需要選擇任何其他屬性。你所需要做的就是確保ng-model表達式引用你想要選擇的選項。例如,在你的控制器:

$scope.selectedAttribute.GC = $scope.tableColumns[0]; 

ngModel創建一個雙向綁定:

  • 您選擇一個選項,並$ scope.selectedAttribute.GC設置爲選定的項目
  • 你$ scope.selectedAttribute.GC的值設置爲的選項之一,該選項將成爲選擇一個
+0

selectedAttribute.GC在文本區域中具有值。但仍未選擇。 – bhushanvinay

+0

select的ngModel引用$ scope.tableColumns中的元素。這個元素是一個對象,而不是一個字符串。文本區域的模型是一個字符串。所以textarea的模型不能是$ scope.tableColumns的任何元素。 –