How to find unique values in Observable for specific property?
Here is my angular 2 component:
import { Component, OnInit, EventEmitter, Output } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { User } from '../../models/user';
import { UserService } from '../../services/user.service';
@Component({
moduleId: module.id,
selector: 'user-list',
templateUrl: 'user-list.component.html'
})
export class UserListComponent implements OnInit {
users: Observable<User[]>;
uniqueGroup: any[];
constructor(private userService: UserService) { }
ngOnInit() {
this.getUsers();
this.getUniqueGroup();
}
getUsers(value?: string) {
this.users = this.userService.getUsers(value);
}
getUniqueGroup() {
this.uniqueGroup=this.users.forEach // I'm stuck here,
//I can't get the unique Group values from users observable and assign them to the uniqueGroup array.
}
}
Let say if the users observable have the following values ( I'm not sure how to draw the observable - I just put them in array to simplify what I want):
users = [{
Group: 'A',
Name: 'SD'
}, {
Group: 'B',
Name: 'FI'
}, {
Group: 'A',
Name: 'MM'
}, {
Group: 'B',
Name: 'CO'
}];
I would like to get a new array of unique values for Group property.
I want to get ['A','B'].
Hope I put my question in a easy to understand way :)