如何设置选项元素title属性在选择绑定到AngularJs模型? [英] How to set title attribute for option elements in a select bound to a model with AngularJs?
本文介绍了如何设置选项元素title属性在选择绑定到AngularJs模型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在我的html绑定到NG-model的select元素。
I have a select element in my html bound to an ng-model.
事情是这样的例子:
<select data-ng-model="accountType" data-ng-options="at.name for at in accountTypes"> </select>
我accountTypes是这样的:
My accountTypes would look like this:
accountTypes:[
{ name:'Individual', value: 1, title: 'Individual Account'},
{ name: 'Joint', value: 2, title: 'Joint Account'}
];
我如何能实现最终的标记,看起来像这样一旦模式势必:
How can I achieve the final markup to look like this once the model is bound:
<option value="1" title="Individual Account">Individual</option>
<option value="2" title"Joint Account">Joint</option>
PS:jQuery的黑客AP preciated但我的理想的解决办法的东西(jQuery的,DOM的修改)少
PS: jQuery hacks appreciated but my ideal solution would something (jQuery, DOM-modification)less.
推荐答案
ngOptions目前不支持的标题的。相反,使用上的选项标签,或(硬)延长ngOptions一个ngRepeat来支持您的需求。
ngOptions doesn't currently support title. Instead, use a ngRepeat on an options tag, or (harder) extend ngOptions to support your needs.
<select ng-model="accountType">
<option ng-repeat="at in accountTypes" value="{{ at.value }}" title="{{ at.title }}"</option>
</select>
这篇关于如何设置选项元素title属性在选择绑定到AngularJs模型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文