繁体   English   中英

如何在Angular JS中获取选择选项文本不值

[英]How to get select option text not value in angular 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>

请与我分享您的知识。 提前致谢

如果要同时使用value.Name as value.Name for value in myOptions使用value.Name as value.Name for value in myOptions作为value。

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 (eg 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> 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM