如何比较日期和显示即将到来的周数据?

时间:2017-12-09 07:18:48

标签: angular ionic2

要求 - 我想显示即将到来的一周的数据。 当前位置 - 下面是我的html代码,我使用* ngIf来比较deadline_date(list.deadline_dt)和今天的日期(this.datt1)。我使用了日期格式(dd-MM-yy)但是它没有比较两个日期。所以,我使用'timeAgo'。但它仍然不起作用。

<ion-card>
<ion-card-header>
  Upcoming Week Tasks to do
</ion-card-header>
<ion-card-content>
  <!-- Add card content here! -->

  <ion-list *ngFor="let list of dataa" >

    <ion-item class="desc" *ngIf="(list.DEADLINE_DT | timeAgo) >= (this.datt1 | timeAgo)">
      <p style="color:#9ea5a9; margin-top:10px" item-start>{{list.TASKDESC}}</p>
      <p style="color:green"> {{list.DEADLINE_DT}} </p>
      <p style="color:#9ea5a9; margin-top:10px" item-end>{{list.ENTUSR }}</p>
      <hr/>

    </ion-item>

  </ion-list>

</ion-card-content>

.ts

public datt=new Date();
 this.datt1=this.datepipe.transform(this.datt,'dd-MMM-yy');
console.log(this.datt1,"sysdat");

enter image description here

1 个答案:

答案 0 :(得分:0)

我猜测timeAgo管道告诉你过去的时间有多远?我认为我们不需要那样做。您想显示即将到来的即将到来的一周。此外,您不需要通过任何方式管道Date对象以比较两个日期。你可以直接比较它们。

我猜测问题是你将它与this.datt1进行比较。这是组件/页面类的属性吗?如果是这样,您不应该使用this,只需使用datt1引用它。