Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/26.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.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
Angular 角度材质日历,要自定义日期css,dateClass不适用_Angular - Fatal编程技术网

Angular 角度材质日历,要自定义日期css,dateClass不适用

Angular 角度材质日历,要自定义日期css,dateClass不适用,angular,Angular,我用的是有棱角的材料日历。我使用了带有日期和类型的示例数据。根据类型,日期的颜色应不同。例如: {date: 2010-07-04, type: Holiday} for holiday color:-green. {date:2019-10-10, type:outage}, for type:-outage, apply color:-red 。 我面临的问题是,css适用于某些日期和类型,而不是所有日期和类型 <div class="row-item" *ngFor="let

我用的是有棱角的材料日历。我使用了带有日期和类型的示例数据。根据类型,日期的颜色应不同。例如:

{date: 2010-07-04, type: Holiday} for holiday color:-green.
{date:2019-10-10, type:outage}, for type:-outage, apply color:-red
。 我面临的问题是,css适用于某些日期和类型,而不是所有日期和类型

  <div class="row-item" *ngFor="let month of months">
        <mat-calendar [dateClass]="dateClass()" [startAt]="month" [selected]="selectedDate"
          (selectedChange)="onSelect($event)"></mat-calendar>
      </div>

以下是stackblitz链接:-

Css的样式为style.Css


Css不适用于所有类型。

您有一个非常复杂的dateClass函数,请使用类似的函数

dateClass() {
    return (date: Date): MatCalendarCellCssClasses => {
      //we get the value in date in format yyyy-MM-dd
      const dateSearch=date.getFullYear()+'-'+
                      ('0'+(date.getMonth()+1)).slice(-2)+'-'+
                      ('0'+date.getDate()).slice(-2)

      //search in the array
      const items=this.datesArray.find(x=>x.date==dateSearch)

      //return if found it, the "type", else null
      return (items?items.type:null)

    };
  }

如果日期的可链接性为真,abput如何应用css类“可链接”?我在数组const items=this.datesArray.find中尝试了这个`//搜索(x=>x.date==dateSearch);const item=this.datesArray.find(y=>y.linkable)//如果找到它,则返回“type”,否则返回null(items?items.type:null,item?'linkable':“”)`您可以返回
items?items.type+(items.linkable?'linkable':“”):null
我给了linkable:-.linkable{文本装饰:下划线!重要;}但是它不适用,我在DOM中看到了这个类。如果linkable为true,则在dateuse
.linkable>.mat日历正文单元格内容{文本装饰:underline!important;}
查看stackblitz分叉