2017-05-10 81 views
1

我需要比較兩個日期,我用這種方法使用ngif 但它不工作* ngif比較日期與角2

<ion-row *ngFor="let ch of cheval1 "> 
     {{ch[0].annee }} 
      <ion-col *ngFor="let m of members"> 
       <b *ngIf="ch[0].annee == m.Course.date |date : 'yyyy' "> {{m.Course.date |date : 'yyyy' }} </b> 
      </ion-col> 
     </ion-row> 
+1

嘗試在大括號包裹它:'* ngIf = 「CH [0] == .annee(m.Course.date |日期: 'YYYY')」' – PierreDuc

+0

謝謝你..它的工作 –

回答

2

您還可以使用*ngIf在組件調用了一個函數:

<ion-row *ngFor="let ch of cheval1 "> 
    {{ch[0].annee }} 
    <ion-col *ngFor="let m of members"> 
     <b *ngIf="yearsAreEqual(ch[0].annee, m.Course.date)"> {{m.Course.date |date : 'yyyy' }} </b> 
    </ion-col> 
</ion-row> 


yearsAreEqual(year, date){ 
    return year === date.getFullYear(); 
} 
+0

謝謝你@泰勒 –

+0

嗨泰勒,請你能幫我解決我的問題嗎 –

+0

嗨,請你能幫我解決我的問題:http://stackoverflow.com/questions/43919676/calculating-sum-of-elements-by-date-in-angular-2-and-ionic-2-ngfor –