Default select Angular

1
 <select class="ui search dropdown" ng-model="vm.empresa" ng-options="item.id as item.label for item in vm.collectionData.items track by item.id" required >
   <option value="">Selecione uma Empresa</option>
 </select>

How do I leave the first item already selected by default?

    
asked by anonymous 01.08.2016 / 13:55

1 answer

1

Make a ng-init to select the first element:

<select class="ui search dropdown" ng-init="vm.empresa = vm.collectionData.items[0]" ng-model="vm.empresa" ng-options="item.id as item.label for item in vm.collectionData.items track by item.id" required >
   <option value="">Selecione uma Empresa</option>
 </select>

so your model will receive the first item in the list.

    
01.08.2016 / 14:14