簡體   English   中英

Angular 7 在創建時間超過 6 個月時隱藏 div

[英]Angular 7 Hide a div when created time is more than 6 months

在 Angular 7 中,我想根據創建的時間隱藏一個 div,如果它已經過去 6 個月那么我想隱藏一個 div 如何修改 html 以在創建時間超過 6 個月時隱藏 div

HTML。

<div class="request"  *ngIf="request.status != 'CANCELLED' && request.duration">

Typescript /** 加載任務的持續時間 */

private getRequestDuration(request) {
    let createdDate = new Date(request.createTime);
    let timeInMilliSeconds = this.currentDate.getTime() - createdDate.getTime();
    let seconds = timeInMilliSeconds / 1000;
    let minutes = seconds / 60;
    let hours = minutes / 60 + 5; // FIXME: EST Offset
    hours = hours > 0 ? hours : 0; // FIXME: Hack to address time-stamp conversions / daylight savings time
    let days = hours / 24;
    return (days q> 0 ? Math.floor(days) + ' days, ' : '') + Math.floor(hours % 24) + ' hours';
}
requests.duration = this.getRequestDuration(requests);

Request Object
Object
agingCurrent: 121777671
agingTotal: 121902671
createTime: "2020-09-14T06:49:20"
createdBySso: "503184132"
duration: "1 days, 20 hours"
indErrored: false
indSavedToMdm: "TRUE"
indSubscribed: "TRUE"
partyId: "160598"
requestId: 627723
requestType: "Internal subscribe"
riskCategory: "ONE"
riskLevel: "MODERATE"
state: {status: "Active", label: "-"}
status: "APPROVED"
statusUpdateTime: "2020-09-14T06:51:25"
supplierId: "S18961"
supplierName: "LM Wind Power (Spain) SA"
transactionId: null
type: "SUBSCRIBE_INTERNAL"
updateTime: "2020-09-14T06:51:25"
version: 15

.ts 文件內

public date = new Date();
public six_month_before_date = this.date.setMonth(this.date.getMonth() - 6);
//**convert request.createTime to Date object before compare**//
request.createTime=new Date(request.createTime)



 

.html 文件內

<div class="request"  *ngIf="request.createTime>six_month_before_date">
<!-Only then display data-->
</div>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM