css - 当时间不可用时,css 如何在日历中应用红色

标签 css angular angular-ng-if

我想在应用背景红色时显示不可用时间,这是一张图片 说明我想做什么

enter image description here

我有工作时间,例如 8 小时到 17 小时, 如果其中一个小时不可用,我想应用红色,我该怎么做? 我想将我的日期“heure”保存到 Array JSON 中?还是直接 JSON ? 这是我尝试过的方式

  constructor(private _calendar: CalendarModel) {
    let plageJour = this.trancheFin - this.trancheDeb;

    for (let i = 0; i < plageJour; i++) {
      this.libelleTranche.push({"heure":"i + this.trancheDeb","unvailable":true});
    }

  }

如果时间不可用,我会申请

    <a *ngIf="???" [ngStyle]="{background:invailable}">
        {{ heure }}H-{{heure+1}}H
    </a>

import { Component, OnInit } from '@angular/core';
import { CalendarModel } from '../calendar-model';

@Component({
  selector: 'app-heure',
  templateUrl: './heure.component.html',
  styleUrls: ['./heure.component.css']
})
export class HeureComponent implements OnInit {

  invailable="red";
  trancheDeb: number = 8;
  trancheFin: number = 17;
  dateNow0: number;//le début du jour d'aujourdh'ui à 00H en timestamp

  libelleTranche = new Array(); //calculé fin de tranche - debut de tranche

  constructor(private _calendar: CalendarModel) {
    let plageJour = this.trancheFin - this.trancheDeb;

    for (let i = 0; i < plageJour; i++) {
      this.libelleTranche.push(i + this.trancheDeb);
    }

  }

最佳答案

思路是对的,但是有几点不对:

  • 在您的模板中,您编写了 inavailable 而不是 heure.unavailable

  • {"heure":"i + this.trancheDeb"} 应该是 {"heure": i + this.trancheDeb}

  • { background : heure.unavailable } 只会产生 { background : true } { background : false } 赢了做任何事情。

相反,设置一个类:

<a [class.red]="heure.unavailable">

或者:

<a [ngClass]="{ red : heure.unavailable }">

在 CSS 中:

a.red{
  background-color : red;
}

关于css - 当时间不可用时,css 如何在日历中应用红色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49893690/

相关文章:

html - 如何保持列表的垂直对齐方式一致?

javascript - Sweet alert 2 的自定义样式

javascript - Angular typescript 的indexOf

javascript - *ngIf 不会在 else block 中切换回 false

javascript - 如何在 ngIf 中使用相同的模板

html - 链接到由 IMG 标签嵌入的 SVG 中的 CSS

html - div 中的图像在图像下方有额外的空间

html - Angular Flex 布局不适用于子组件

javascript - Angular 绑定(bind)到 View 上的函数会导致对数据服务的无限调用

angular - Protractor 无法从 executescript 中获取值(value),它返回一个 promise