问题
I have a select element in my html bound to an ng-model.
Something like this example:
<select data-ng-model="accountType" data-ng-options="at.name for at in accountTypes"> </select>
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 hacks appreciated but my ideal solution would something (jQuery, DOM-modification)less.
回答1:
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>
来源:https://stackoverflow.com/questions/21208976/how-to-set-title-attribute-for-option-elements-in-a-select-bound-to-a-model-with