in angularjs i have a ui-select
:
<ui-select ng-model="itemSelected.selected" theme="selectize" ng-disabled="disabled">
<ui-select-match placeholder="Select an item...">{{$select.selected.Name}}</ui-select-match>
<ui-select-choices repeat="item in itemsList">
<span ng-bind-html="item.Name"></span>
</ui-select-choices>
</ui-select>
How can i select an item from code when i load the page?
When i load the page in the controller i get the $scope.itemsList
: how can i select a specific item from the controller
?
Thanks
The plunkr by @Pankaj Parkar was no longer working for the intended usage so I forked it and got it working here:
http://plnkr.co/edit/Y6cdgJQ3YPq7Ncb3bT4A?p=preview
The key changes involved actually setting the selected item in the controller:
The key addition is
$scope.address.selected = $scope.addresses[0];
and$scope.refreshAddresses('New York, NY');
to get it to go.I also updated the other selects to prepopulate, as well.
You can set that on controller load itself
Markup
Code
Working Plunkr