In my NgClass function, I make use of an array that is populated in the ngOnInit lifecycle hook.
Within ngOnInit, the prepareRezerwation() function creates a variable called colorRezerwation:
this.nodeService.getRezerwations(this.minMax).subscribe(rezerwations => {
this.prepareRezerwation(rezerwations);
// this.functionsService.showRezerwation(post, this.openingHours);
// this.showSpinner = false;
}, error => {
console.log("Connection problem")
});
In the HTML template, I apply the function setColor(1,i) using [ngClass]:
<ng-container matColumnDef="big">
<th mat-header-cell *matHeaderCellDef class="xunk-calendar-cell"></th>
<td mat-cell *matCellDef="let element; let i = index" [ngClass]="setColor(1,i)">Name</td>
</ng-container>
The setColor(1,i) function is defined as follows:
setColor(colIndex, rowIndex){
this.colorRezerwation.position.forEach(arrayItem => {
if(arrayItem.column === colIndex && arrayItem.row === rowIndex){
return {'reservation': true}
}
});
}
When I remove the forEach loop entirely, the function works correctly.
I appreciate all the assistance provided. Thank you!