2015-05-26 30 views
0

獲得選擇選項的文本不值這裏是我的代碼如何角JS

<div class="form-group"> 
    <label class="control-label">Student Name: <span class="req-field">*</span> 
    </label> 
    <select ng-change="selectAction()" ng-model="formData.Name" ng-options="value.CompleStuId as value.Name for value in myOptions" class="form-control" required> 
    <option value="">-- Select --</option> 
    </select> 
</div> 

請與我分享你的知識。在此先感謝

+0

Sujeet,我們將需要更多的東西。也許你在plunkr或jsfiddle上試過的一個例子... – zkristic

+0

你是否在尋找沒有價值或選定價值的文字? – Vineet

+0

只是學生的名字我想 –

回答

2

如果您希望使用Name作爲標籤和所選值,則您想使用value.Name as value.Name for value in myOptions

ngOptions[docs]

數組數據源:

select as label for value in array 

其中:

value: local variable which will refer to each item in the array or each property value of object during iteration. 
label: The result of this expression will be the label for <option> element. The expression will most likely refer to the value variable (e.g. value.propertyName). 
select: The result of this expression will be bound to the model of the parent 

var app = angular.module('app', []); 
 

 
app.controller('myController', function($scope) { 
 
    $scope.formData = {}; 
 
    $scope.myOptions = [{CompleStuId: 1, Name: 'a'}, {CompleStuId: 2, Name: 'b'}, {CompleStuId: 3, Name: 'c'}]; 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script> 
 
<div ng-app='app' ng-controller='myController'> 
 

 

 
<div class="form-group"> 
 
    <label class="control-label">Student Name: <span class="req-field">*</span> 
 
    </label> 
 
    <select ng-change="selectAction()" ng-model="formData.Name" ng-options="value.Name as value.Name for value in myOptions" class="form-control" required> 
 
    <option value="">-- Select --</option> 
 
    </select> 
 
</div> 
 
    
 
    {{ formData.Name }} 
 

 
</div>

+0

嗨朋友看看這個代碼。我希望這對你們來說都足夠了。 http://plnkr.co/edit/wPHc5HuXcTaU7qFkBlrO –

+0

你是沒有填寫你的選擇。你可以在那裏放一些示例數據嗎? 'ng-options =「value.Name as value.Name for value in myOptions」' – DTing

+0

我想從數據庫中選擇獲取課程名稱和聯結的值,點擊提交按鈕保存後選擇學生名稱。 –