S
S
srnsdlmtn2016-08-12 17:44:50
JavaScript
srnsdlmtn, 2016-08-12 17:44:50

How to remove duplicate items in select when using Angular?

A list of products is taken from the database, each product has a category, which may be the same for some products.
In select they are inserted like this:

<select ng-model="chooseCat">
    <option ng-repeat="item in Items">{{item.cat}}</option>
 </select>

But in this way, all categories are displayed in the list, that is, for example:
A
A
B C
A
and
so on
. How can I fix this and remove the matching categories?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Risent Veber, 2016-08-12
@srnsdlmtn

Need a uniqueness filter on the category unique:'cat'

<select 
  ng-options="item as item.cat for item in Items | unique:'cat' track by item.cat" 
  ng-model="chooseCat">
</select>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question