首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >角9动态改变垫排颜色

角9动态改变垫排颜色
EN

Stack Overflow用户
提问于 2020-07-20 13:43:12
回答 1查看 193关注 0票数 0

我比较了两次这样的约会

代码语言:javascript
复制
for (let i = 0; i < 9; i++) {

    this.date1 = formatDate(data.elements[i].date_expiration, 'yyyy-MM-dd', 'fr_FR');
    this.date2 = formatDate(new Date(), 'yyyy-MM-dd', 'fr_FR');
    this.date1 = Date.parse(this.date1);
    this.date2 = Date.parse(this.date2);
    this.result = this.date1 >= this.date2 ? true : false;
    console.log(this.result);
    if (this.date1 >= this.date2) {
        this.isExpire = true;
    } else {
        this.isExpire = false;
    }

}

这个工作很好,我在控制台中看到了一个false和8个true。

代码语言:javascript
复制
<mat-row *matRowDef="let assets; columns: displayedColumns;" [ngClass]=" isExpire ? 'is-red' : 'is-white' "></mat-row>

但我所有的争吵现在都是红色的

怎么了?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-07-20 16:54:34

琼,你有一个数组的对象。您需要向对象添加一个新属性,以了解该对象是否过期(不能使用唯一变量)。为此,在获得数据后使用一个forEach (我想在一个子描述函数中)

代码语言:javascript
复制
data.elements.forEach((x:any)=>{
   //x is the object
    const date1 = formatDate(x.date_expiration, 'yyyy-MM-dd', 'fr_FR');
    const date2 = formatDate(new Date(), 'yyyy-MM-dd', 'fr_FR');
    //you create the new property only write x.nameOfproperty
    //see that, as you formated the data as yyyy-MM-dd, you needn't
    //calculate the real Date,e.g. two string: "2020-02-15" is less than "2020-07-20"
    x.isExpire=date1>=date2
})

然后只需使用新属性“询问”该属性即可。

代码语言:javascript
复制
<mat-row *matRowDef="let assets; columns: displayedColumns;" 
    [ngClass]=" assets.isExpire ? 'is-red' : 'is-white' ">
</mat-row>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62996730

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档