2

Using ui-select, I have list of personels and want to show that in with ui-select by this way:

(function() {
    'use strict';

    angular
        .module('framework')
        .controller('UserDetailController', UserDetailController);

    function UserDetailController(BasePersonel) {
        var vm = this;
        vm.basePersonels = BasePersonel.all();
    }
})();

<ui-select ng-model="vm.basePersonelId" >
    <ui-select-match>
        <span ng-bind="$select.selected.entityTitle"></span>
    </ui-select-match>
    <ui-select-choices repeat="item in (vm.basePersonels | filter: $select.search) track by item.id">
        <span ng-bind="item.entityTitle"></span>
    </ui-select-choices>
</ui-select>

But I want to set id of the selected object into vm.basePersonelId instead of the whole object.

How can i do that?

Michael W. Czechowski
  • 3,366
  • 2
  • 23
  • 50
Rasool Ghafari
  • 4,128
  • 7
  • 44
  • 71

1 Answers1

1

Change your repeat from this

repeat="item in (vm.basePersonels | filter: $select.search) track by item.id"

to this:

repeat="item.id as item in (vm.basePersonels | filter: $select.search) track by item.id"

See more here

lealceldeiro
  • 14,342
  • 6
  • 49
  • 80