2016-12-29 100 views
1

我有一個價格標籤的項目列表,我有一個選擇在頂部的選項,現在我想顯示價格比選定的選項更多的項目。這是我的代碼,如果我選擇10000然後我會得到超過10000的所有項目,但我也有幾個項目小於10000例如:6520,9200等。我認爲它只比較第一個數字,請讓我知道我哪裏錯了。 謝謝。離子2:篩選

 <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> 
+2

難道你的過濾器,價格或兩者都是字符串?嘗試使用Number(pricefilter)和Number(content.price)來確保您正在比較數字。 –

回答

2

雅嘗試這個

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

content.price * 1這會使它成爲一個數字,這將分叉罰款

+1

謝謝你這個工作正是我想要的:) – inoxe

+0

爲什麼你只是發表相同的答案!!!!!!!? –

2

的快速方法是這樣的:

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

,但你可以轉換content.price在TS文件

+0

謝謝你這個工作。 :) – inoxe