Open
Description
See http://codepen.io/caseyjhol/pen/dPRXBN
Example:
scope.colors = [{ id: 10, name: 'Red' }, { id: 20, name: 'Green' }, { id: 30, name: 'Blue' }];
<select selectpicker ng-model="selected" ng-options="c.name for c in colors track by c.id"></select>
When an option is selected, the value of the select is set to the object, rather than the track by property. So, selecting "Green" from the list sets the value to {id: 20, name: 'Green' }
, instead of 20
.
I created a workaround by implementing a trackBy attribute and altering the refresh
function.
function refresh(newVal) {
$timeout(function () {
if (attrs.ngOptions && /track by/.test(attrs.ngOptions)) {
if (attrs.trackBy && newVal) {
element.val(newVal[attrs.trackBy]);
} else {
element.val(newVal);
}
}
element.selectpicker('refresh');
});
}
<select selectpicker ng-model="selected" ng-options="c.name for c in colors track by c.id" track-by="id"></select>
This isn't ideal and doesn't work when tracking by $index
, but it works for me for now.
Metadata
Metadata
Assignees
Labels
No labels