kalombo
kalombo

Reputation: 869

How to avoid duplicates in multiple angular ui select

I have a multiple ui-select widget and i need to update the choices by click on update button.

<ui-select multiple ng-model="multipleDemo.selectedPeople" theme="select2" ng-disabled="disabled" style="width: 800px;">
    <ui-select-match placeholder="Select person...">{{$item.name}} &lt;{{$item.email}}&gt;</ui-select-match>
    <ui-select-choices repeat="person in people | propsFilter: {name: $select.search, age: $select.search}">
        <div ng-bind-html="person.name | highlight: $select.search"></div>
            {{person.email}}
    </ui-select-choices>
</ui-select>

If i use array of strings for people variable it works fine. But when i use array of objects then duplicates appears in choices. Here is the snippet http://plnkr.co/edit/Jbhv1stbXEdNnt3of5aW?p=preview How can i avoid duplicates with objects? Help please.

Upvotes: 3

Views: 2306

Answers (1)

t0mpl
t0mpl

Reputation: 5025

solution i've found here https://github.com/angular-ui/ui-select/issues/580. You can filter the data you receive from your API.

$scope.people = response.data.data.filter(function (i) {
    return $multipleDemo.selectedPeople.map(function (e) { return e.id; }).indexOf(i.id) < 0; 
}

Upvotes: 2

Related Questions