Dropdown already selected

Asked

Viewed 318 times

0

I dropdown with Angularjs in the following way

<ui-select ng-model="SelectedItem.LegalEntity" 
            theme="bootstrap"
            reset-search-input="false"
            style="width: 100%"
            id="legalEntityId"
            ng-disabled="disabled">
           <ui-select-match placeholder="">{{$select.selected.Name}}</ui-select-match>
               <ui-select-choices repeat="entity in legalEntities">
                <div ng-bind-html="entity.Name | highlight: $select.search"></div>
               </ui-select-choices>
           </ui-select>

When the dropdown has only 1 item in the list, I want to block the dropdown and leave the first item already selected.

I can already lock using ng-disable, but I couldn’t load the page with the first dropdown item selected.

  • a Working fiddle was great to be easier. Anyway, the ui-select has no property selected ? if yes, supposedly the ng-selected="expression" should be enough

  • i use <ui-select-Choices repeat="Entity in legalEntities">

1 answer

1


to preload the ui-select with some value just assign the list to the ng-model variable in the controller:

var legalEntities = [{Name: 'nameDaEntity'}];

$scope.SelectedItem.LegalEntity = legalEntities;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.