I want to filter data based on drop down of the range of price example first drop down should be:- $15 so that filter data should be lower or equal to $15 and drop down should show $15. If second is $15-$50 then how I show data in drop down $15-$50 and filter accordingly. What I tried is here but couldn't get what I want. Here is what I tried and still trying to get the desired result, Hope someone could help me.
.html file is
<form [formGroup]="myForm">
<select name="Price" formControlName="filterProduct">
<option *ngFor="let k of PriceFilter | groupBy: 'Value' | keyvalue">
<div>
<ng-container *ngFor= "let i of k['value']">
<span>{{i['DisplayText']}}</span>
</ng-container>
</div>
</option>
</select>
</form>
and here is my component
PriceFilter = [
{
"TagId": 20,
"Type": "Budget",
"Value": 5,
"Values": null,
"DisplayText": "$50",
"Order": null
},
{
"TagId": 20,
"Type": "Budget",
"Value": 15,
"Values": null,
"DisplayText": "$15",
"Order": null
}]
Stores = [
{
"Products": [
{
"ProductId": 206419,
"Price": 39.99,
"PriceLabel": "$39.99",
"ProductTags": [1,2]
},
{
"ProductId": 206419,
"Price": 3.99,
"PriceLabel": "$9.99",
"ProductTags": [1,2]
}
]}] // can add more fake data to it for testing
constructor(private fb: FormBuilder) {
this.myForm = this.fb.group({
filterProduct: ['']
})
}
ngOnInit() {
this.myForm.get('filterProduct').valueChanges.subscribe(
value => {
this.Stores.forEach(x => {
console.log(x.Products.filter(val => value.slice(1) >=
val['Price']))
})
// this.Products.filter(val => value.slice(1) <= val['Price'])
}
)
}