AngularJS - 选择标记 - 从选项中获取属性 [英] AngularJS - select tag - getting attribute from option when selected

查看:70
本文介绍了AngularJS - 选择标记 - 从选项中获取属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有一个选择标签,显示一些选项,我希望当选择一个选项时,它需要 data-something 属性并粘贴其值(属性) )在我有的输入元素。它只是示范,值属性应该以表格形式发送。

So I have a select tag that shows some options and I wish that when an option is selected it takes the data-something attribute and pastes its value (of the attribute) in the input element I have. It is only demonstrative, value attribute should be send in the form.

<input ng-model="refreshedByExample" type="text">
<select ng-model="example">
    <option value="1" data-something="valueForRefreshedByExample1">1</option>
    <option value="2" data-something="valueForRefreshedByExample2">2</option>
    <option value="3" data-something="valueForRefreshedByExample3">3</option>
</select>

任何想法?

非常感谢每个人

推荐答案

使用正确的代码更新答案

Updating the answer with correct code

<input ng-model="refreshedByExample" type="text">
<select ng-model="example" ng-change="refreshByExample=example"> 
    <option ng-value="valueForRefreshedByExample1">1</option> 
    <option ng-value="valueForRefreshedByExample2">2</option> 
    <option ng-value="valueForRefreshedByExample3">3</option> 
</select>

参见 ng-value

还可以考虑使用 ng-options 如果您的值包含在数组中。

Also consider using ng-options if your values are contained in a array.

这篇关于AngularJS - 选择标记 - 从选项中获取属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆