Angular 对函数没有任何反应
我在NgClass中使用了一个函数,该函数使用ngOnInit填充的数组 ngOnInit->prepareRezerwation()createcolorrezwationveriable:Angular 对函数没有任何反应,angular,typescript,ng-class,Angular,Typescript,Ng Class,我在NgClass中使用了一个函数,该函数使用ngOnInit填充的数组 ngOnInit->prepareRezerwation()createcolorrezwationveriable: this.nodeService.getRezerwations(this.minMax).subscribe(rezerwations => { this.prepareRezerwation(rezerwations); // this.functionsServi
this.nodeService.getRezerwations(this.minMax).subscribe(rezerwations => {
this.prepareRezerwation(rezerwations);
// this.functionsService.showRezerwation(post, this.openingHours);
// this.showSpinner = false;
}, error => {
console.log("Connection problem")
});
html->[ngClass]=“setColor(1,i):
<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>
setColor(colIndex, rowIndex){
this.colorRezerwation.position.forEach(arrayItem => {
if(arrayItem.column === colIndex && arrayItem.row === rowIndex){
return {'reservation': true}
}
});
}
当我跳过整个forEach返回时,它工作正常
感谢您提供的所有帮助。您正在将函数中的类变量返回到forEach循环,而不是setColor函数
setColor(colIndex,rowIndex){
this.colorRezerwation.position.forEach(arrayItem=>{
if(arrayItem.column==colIndex&&arrayItem.row==rowIndex){
-->返回{'reservation':true}{
if(arrayItem.column==colIndex&&arrayItem.row==rowIndex){
类={'reservation':true}
}
});
返回舱;
}