Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 863
kalombo Avatar asked Aug 09 '26 00:08

kalombo


1 Answers

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; 
}
like image 169
ThomasP1988 Avatar answered Aug 11 '26 23:08

ThomasP1988