Search code examples
angularjsselectglyphicons

Select - options and AngularJS - add glyphicon to options


I use this select - options in my AngularJS application:

<select data-ng-model="userFilter" data-ng-options="c as c.firstname + ' ' + c.surname for c in vm.users">
    <option></option>
</select>

and now I will add a glyphicon to each option value:

<span class="glyphicon glyphicon-user"></span>

is there a possibility to do it like this?


Solution

  • I don't know a way with ng-options, though you could use ng-repeat:

    <select data-ng-model="userFilterIndex" data-ng-change ="userFilter = vm.users[ userFilterIndex ]">
    
        <option data-ng-repeat="c in vm.users" value="{{ $index }}">
            <span class="glyphicon glyphicon-user"></span>
            {{ c.firstname + ' ' + c.surname }}
        </option>
    
    </select>