javascript - Javascript /Typescript/Angular 根据创建时间隐藏 div
问题描述
我在 Angular 7 中有一个动态表数据行,如果它是 6 个月前创建的,我想隐藏一条记录。我试过这样,现在仪式它隐藏所有记录而不考虑创建时间,任何人都可以更正 ngIf 条件并输入脚本代码,以便它只隐藏 6 个月前创建的记录
HTML
<div class="request" *ngIf="request.duration > six_month_before_date">
打字稿
public date = new Date() ;
public six_month_before_date= this.date.setMonth(this.date.getMonth() -6);
private getRequestDuration(request) {
console.log(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 > 0 ? Math.floor(days) + ' days, ' : '') + Math.floor(hours % 24) + ' hours';
}
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
__proto__: Object
解决方案
听起来您只需要对以下内容进行一些调试:
*ngIf="request.createTime > six_month_before_date">
我解决这个问题的最简单方法是Debugging
将其替换为以下内容:
*ngIf="foo(request.createTime)
并在您的 ts 创建一个函数:
foo(requestCreatedTime) {
console.log(this.date.setMonth(this.date.getMonth() -6));
console.log(requestCreatedTime);
return (this.date.setMonth(this.date.getMonth() -6);
}
这让您可以查看 ngIf 中使用的值,以确定它们是否符合您的预期。
推荐阅读
- python - python中的复杂函数和3D图形序列
- android - 如何自定义状态栏图标和文字颜色?例如状态栏背景:白色,状态栏图标颜色,文本:红色
- php - Laravel Eloquent - 过滤关系
- c++ - 如何在 cpprest sdk 中将字节数组作为正文数据流式传输?
- java - 使用接口的独占方法进行比较,没有 if 块
- r - “无法分配向量”,但向量似乎很小
- ios - UIProgressView 向后进展
- r - 更改单个模块中的输入时如何更改多个 Shiny 模块的输入?
- node.js - DiscordAPIError:无法发送空消息。但是我可以记录我试图发送到控制台的东西,发送的数据来自 MongoDB
- java - 为什么 java.io.File 对象集合的数据不会显示在 JSP forEach 标记中?