Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular UI Select, Unique values pre-selected array

Lets say I have want to edit an existing entity that has an array of values that are also part of the selectable values. e.g.

var preSelectedLanguages = [
    {id: 2, iso: "de"},
    {id: 3, iso: "fr"}
]

var languages = [
    {id: 1, iso: "en"},
    {id: 2, iso: "de"},
    {id: 3, iso: "fr"},
    {id: 4, iso: "it"},
    {id: 5, iso: "us"}
]

My ui-select directive would be something like:

<ui-select multiple ng-model="preSelectedLanguages">
    <ui-select-match placeholder="Select language...">
        {{$item.iso}}
    </ui-select-match>
    <ui-select-choices repeat="l in languages track by language.id">
        {{language.iso}}
    </ui-select-choices>
</ui-select>

However the ui-select-choices option list cant seem to remove the duplicates, even though I have used track by language.id.

Any idea how to do this correctly?

like image 929
ChrisGeo Avatar asked Oct 31 '22 00:10

ChrisGeo


1 Answers

It works for me in this way

<ui-select multiple ng-model="preSelectedLanguages">
    <ui-select-match placeholder="Select language...">
        {{$item.iso}}
    </ui-select-match>
    <ui-select-choices repeat="l in languages track by l.id">
        {{l.iso}}
    </ui-select-choices>
</ui-select>
like image 184
José García Avatar answered Nov 11 '22 13:11

José García