2017-05-10 140 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 –