0

I am getting tests values from remote server, GroupID values can be duplicated, but I wish my dropdown will show values without duplication, I tried the following code, which is not working

<th>
<select class="form-control" (change)="reloadPosts({ GroupID: u.value })" #u>
<option value="">Select group id...</option>
<template *ngFor="let test of tests"> <option *ngIf="!test" value="{{ test.GroupID }}">
{{ test.GroupID }}
</option></template>
</select>
</th>   

how can I do it with angular rc5 and above

thanks

Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
Shay Binyat
  • 115
  • 1
  • 1
  • 9

2 Answers2

0

You should be able to do this with a simple pipe...

@Pipe({ name: 'unique', pure: false })

export class UniquePipe implements PipeTransform {
    transform(value: any, args: any[] = null): any {
        return _.uniq(value);
    }
}

Then in your html use *ngFor="let test of tests | unique"

The pipe example uses underscore.js but feel free to write the filter any way you'd like.

More information on pipes.

Rob
  • 12,659
  • 4
  • 39
  • 56
0

I was unable to solve this using pipe, so I modified my component code, see: Angular2, create new array/map

Community
  • 1
  • 1
Shay Binyat
  • 115
  • 1
  • 1
  • 9