AngularJS:如何获取select的值和标签?

AngularJS:如何获取select的值和标签?,angularjs,Angularjs,我正在使用带有ng模型属性的select标记。我得到ng模型中所选元素的值。如何才能同时获取选定元素的标签。 我想检索标签及其值。谢谢。我猜您要么使用ng repeat创建选择,要么在模板中手动键入选择。如果在同一模型中设置标签和值,则可能会出现这种情况。如果您有: $scope.choices = { "choiceone" : "The first Choice", "choicetwo" : "The second Choice", "choicethree" :

我正在使用带有ng模型属性的select标记。我得到ng模型中所选元素的值。如何才能同时获取选定元素的标签。
我想检索标签及其值。谢谢。

我猜您要么使用ng repeat创建选择,要么在模板中手动键入选择。如果在同一模型中设置标签和值,则可能会出现这种情况。如果您有:

$scope.choices = {
    "choiceone" : "The first Choice",
    "choicetwo" : "The second Choice",
    "choicethree" : "The third Choice"}
您可以这样实现它们:

<select ng-model="choice">
    <option ng-repeat="(key, value) in choices" value="{{key}}">{{value}}</option>
</select>

{{value}}
但是,这不是使用select指令的最佳方式(假设您正在这样做)。select指令具有ng options属性,该属性以更简洁的方式定义值和标签。我已经编辑了文档中关于这个主题的示例Plunkr,包括ngRepeat的示例用法:

在此处查看ng选项选项卡上的文档: