How to select a specific object by default?
Closed this issue · 5 comments
I am using this nice control, to view a list of objects { id: 0, title: "Item Title"}, which works fine, but how would I display the control when loading the page, and have a specific item selected by default?
In you controller, you could have something like
$scope.items = [{ id: 0, title: "Item Title"}];
$scope.selected = $scope.items[0];
And in your view:
<div custom-select ng-model="selected" ng-options="i for i in items"></div>
It is important that when you select a value by code, you do so by referencing the item in the source array, as opposed to creating a separate object.
It do not working with angular >= 1.4, using cs-options and async
Yes, I noticed that there are important changes in Angular 1.4 in the way select
and ng-options
work. The mechanism this directive uses to replicate model changes back to the view is not working properly for version 1.4 and up.
There is a new branch where this issue should be fixed. Note that the usage has changed (please re-read the short examples). I plan to merge this branch into the master as soon as I validate it doesn't have any issues.
Closed due to inactivity.