获取Angular ng选项下拉列表的选定文本 [英] Get Selected Text of Angular ng-option dropdown list
本文介绍了获取Angular ng选项下拉列表的选定文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的角码中有这个下拉列表:
I have this drop-down list in my angular code:
<div class="btn-group" dropdown>
<select class="selected_location" ng-options="perlocation.id as perlocation.name for perlocation in locations" ng-model="cleaningServiceLocation">
<option value="">Please Select Location</option>
</select>
<div>
现在在我的控制器中,我可以轻松调用所选值:
Now in my controller I can easily call the selected value as:
$scope.cleaningServiceLocation
我可以得到文本,或在我的情况下,选定的位置的名称?
How can I get the text, or in my case, the name of the selected location?
推荐答案
您可以使模型(perlocation)作为object而不是(perlocation.id) -
You can make model (perlocation) as object instead of (perlocation.id)-
<select class="selected_location" ng-options="perlocation as perlocation.name for perlocation in locations" ng-model="cleaningServiceLocation">
并将其作为 -
$scope.cleaningServiceLocation.name
这篇关于获取Angular ng选项下拉列表的选定文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文