I am trying to create a calendar view from scratch using angular. I had done with displaying all dates of the month dynamically. My problem here is I need to show different background colors for the weekend dates such as Friday and Saturday using Moment I had searched on the internet I could not find any resource to help me with this. In addition to that, I need to display the days inside the first row and not as a separate row in my calendar view. My appcomponent.html code
<div class="flex-container flex-center">
<button
mat-icon-button
matTooltip="Previous Month"
[matTooltipPosition]="'above'"
class="iconsSize ml-1 my-auto"
(click)="previousmonth()"
>
<mat-icon>
chevron_left
</mat-icon>
</button>
<h4><b>{{date.format('MMMM ')}}{{date.format('YYYY ')}}</b></h4>
<span class="material-icons" style="padding: 7px; font-size: 20px;">
event
</span>
<button
mat-icon-button
matTooltip="Next Month"
[matTooltipPosition]="'above'"
class="iconsSize ml-1 my-auto"
(click)="nextmonth()"
>
<mat-icon>
chevron_right
</mat-icon>
</button>
</div>
<div class="container-fluid">
<div class="flex-container flex-wrap p-3 m-2">
<div *ngFor ="let day of daysarr">
<div class="calendar-days flex-container flex-center">{{day}}</div>
</div>
</div>
</div>
My appcomponent.ts file
export class AppComponent implements OnInit {
public date = moment();
public daysarr;
constructor() { }
ngOnInit(): void {
this.daysarr = this.createCalendar(this.date);
}
createCalendar(month)
{
let firstDay = moment(month).startOf('M');
let days = Array.apply(null,{length: month.daysInMonth()+1})
.map(Number.call, Number)
.slice(1);
for(let n=0; n < firstDay.weekday(); n++)
{
days.unshift(null);
}
return days;
}
public nextmonth()
{
this.date.add(1,'M');
this.daysarr = this.createCalendar(this.date);
}
public previousmonth()
{
this.date.subtract(1,'M');
this.daysarr = this.createCalendar(this.date);
}
}
appcomponent.css
.calendar-days {
width: 155px;
height: 120px;
background: #fff;
border: 1px solid #ccc;
padding: 3px;
}
.flex-container {
display: -webkit-flex;
display: flex;
}
.flex-center {
-webkit-align-items: center;
align-items: center;
-webkit-justify-content: center;
justify-content: center;
}

