Search code examples
angularionic2ionic2-select

ionic 2 : Filtering


i have a list of items with a price tag and i have a select option at the top , now i want to display item which has the price more than the selected option . this my code if i select 10000 then i will get all items more than 10000 but i also get few items lessthan 10000 for example : 6520 , 9200 etc . i think its comparing only 1st number ,plz let me know where am i going wrong . thank you .

     <ion-item>
        <ion-label>Price</ion-label>
        <ion-select [(ngModel)]="pricefilter">
          <ion-option value="1000">more than 1000</ion-option>
          <ion-option value="5000">more than 5000</ion-option>
          <ion-option value="10000">more than 10000</ion-option>
          <ion-option value="15000">more than 15000</ion-option>
          <ion-option value="20000">more than 20000</ion-option>
        </ion-select>
      </ion-item> 

     <div  *ngFor = ' let content of data ' >
      <ion-card  *ngIf=" (  pricefilter=='' || pricefilter <= content.price )  " > 
        <ion-card-content>       
          <h1> {{ content.price }}
        </ion-card-content>
      </ion-card>
    </div>

Solution

  • ya try out this

    <ion-card *ngIf="(pricefilter=='' || pricefilter <= content.price*1 )">
    

    content.price*1 this will make it a number , this will fork fine