Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 到期后如何更改字体颜色?_Html_Css_Angular_Angular8 - Fatal编程技术网

Html 到期后如何更改字体颜色?

Html 到期后如何更改字体颜色?,html,css,angular,angular8,Html,Css,Angular,Angular8,我想设置颜色时,到期日期尚未达到绿色。但当有效期为红色时 .curentDate{ 颜色:rgb(54、168、54) } .截止日期{ 颜色:红色; } 维护包 {{{getMaPackage(ticket)} 您需要返回颜色变量 setexpirationDate(ticket) { let color = '' const endDate = moment(ticket.site.maEndDate.seconds * 1000).format('L'); co

我想设置颜色时,到期日期尚未达到绿色。但当有效期为红色时

.curentDate{
颜色:rgb(54、168、54)
}
.截止日期{
颜色:红色;
}

维护包

{{{getMaPackage(ticket)}


您需要返回颜色变量

setexpirationDate(ticket) {
    let color = ''
    const endDate = moment(ticket.site.maEndDate.seconds * 1000).format('L');
    const currentDate = new Date()
    const currentDateFormat = moment(currentDate).format('L');
    if (endDate < currentDateFormat) {
      color = 'curentDate'
    } else {
      color = 'expirationDate'
    }
    return color // you need to return the value
  }
setexpirationDate(票据){
让颜色=“”
const endDate=时刻(ticket.site.maEndDate.seconds*1000)。格式('L');
const currentDate=新日期()
const currentDateFormat=时刻(currentDate).format('L');
如果(endDate
您的情况不正确

if (endDate < currentDateFormat) {
      color = 'curentDate'
    } else {
      color = 'expirationDate'
    }
if(endDate
您正在尝试设置日期过期时的颜色绿色,设置相反的颜色红色

解决方案:

<p [ngClass]="{isExpired?'expirationDate':'currentDate'}">{{ getMaPackage(ticket) }}</p>
get isExpired() {
    let color = ''
    const endDate = moment(ticket.site.maEndDate.seconds * 1000).format('L');
    const currentDate = new Date();
    const currentDateFormat = moment(currentDate).format('L');
    return endDate < currentDateFormat;
  }
HTML:

<p [ngClass]="{isExpired?'expirationDate':'currentDate'}">{{ getMaPackage(ticket) }}</p>
get isExpired() {
    let color = ''
    const endDate = moment(ticket.site.maEndDate.seconds * 1000).format('L');
    const currentDate = new Date();
    const currentDateFormat = moment(currentDate).format('L');
    return endDate < currentDateFormat;
  }
{{{GetMapPackage(票证)}

类型脚本:

<p [ngClass]="{isExpired?'expirationDate':'currentDate'}">{{ getMaPackage(ticket) }}</p>
get isExpired() {
    let color = ''
    const endDate = moment(ticket.site.maEndDate.seconds * 1000).format('L');
    const currentDate = new Date();
    const currentDateFormat = moment(currentDate).format('L');
    return endDate < currentDateFormat;
  }
get-isExpired(){
让颜色=“”
const endDate=时刻(ticket.site.maEndDate.seconds*1000)。格式('L');
const currentDate=新日期();
const currentDateFormat=时刻(currentDate).format('L');
返回endDate
您是否尝试添加!颜色重要吗? e、 g


模板中的
票证是什么?它是来自
*ngFor
数组的变量吗?您不需要使用
.format('L')
,因为您使用的是瞬间使用,您使用的是局部变量
color
。您在哪里使用它?您可以使用[ngClass]作为
[ngClass]=“isExpired?”“expirationDate':“currentDate”
是。谢谢@埃利塞