I am getting an Observable. each item have ItemType. items.ItemType have duplicates like Electronics, Household, Electronics. I need a string array having unique ItemType and then select item from select box to display all items that belong to that type. I am new to angular so I apologize in advance.
item.service.ts
getAllItems():Observable<Item[]>{
return this.http.get<Item[]>(this.url+'/AllItems');
}
item.component.ts
items: Observable<Item[]>;
loadAllItems() {
this.items = this.itemService.getAllItems();
}
item.component.html
<mat-select name="ItemType" >
<mat-option *ngFor="let item of items" [value]="item.ItemType">
{{item.ItemType}}
</mat-option>
</mat-select>
<table class="table" >
<tr ngclass="btn-primary">
<th class="tbl2">Name</th>
<th class="tbl2"> ItemType</th>
<th class="tbl2">Price</th>
</tr>
<tr *ngFor="let item of items">
<td class="tbl2">{{item.Name}}</td>
<td class="tbl2">{{item.ItemType}}</td>
<td class="tbl2">{{item.ItemPrice}}</td>
</table>
You should operate directly in the service, applying the map operator against the Observable emitted value:
The filter acts this way:
Check a quick test here: https://jsbin.com/keyitosiqu/edit?js,console