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

3
  • Did it work with RC.4? What values are you using (string, object, ...)? Commented Sep 5, 2016 at 18:57
  • only rc5. - values are strings Commented Sep 5, 2016 at 19:54
  • Try with objects instead or trackBy stackoverflow.com/questions/33363987/… Commented Sep 5, 2016 at 20:01

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.