I have a generic table component and I want to make the row hoverable by binding class using ngClass to a ng-container. However I an error.
The code:
<ng-container *ngFor="let row of manager.rows" [ngClass]="manager.config.onRowSelect ? 'row-selectable' : ''">
<ng-container *ngFor="let cell of row.displayData">
<div (click)="row.onClick(row.item)" class="cell-divider">
<!-- Image -->
<div *ngIf="cell.isImage" class="cell" style="display: flex; align-items: center; padding: 3px;">
<img [src]="cell.data">
</div>
<!-- Data -->
<div *ngIf="!cell.isImage" class="cell">
{{cell.data}}
</div>
</div>
</ng-container>
<!-- Column Actions -->
<div *ngIf="manager.config.rowActions && manager.config.rowActions.length > 0" style="display: flex; gap: 2px; align-items: center;" class="cell-divider">
<div *ngFor="let action of row.actions" >
<ng-container>
<app-ui-icon-button (clicked)="action.action(row.item)" [iconSize]="20" [tooltip]="action.tooltip" [backgroundTransparent]="true" [iconColor]="action.color" [icon]="action.icon"></app-ui-icon-button>
</ng-container>
</div>
</div>
</ng-container>
The error I get:
If I remove the ngClass part from the 1st ng-container then I don't get the error.
Solutions that won't work:
- Replace the ng-container with a div, because above the ng-container is a table layout and it will ruin the layout.
- Add a div between the 1st ng-container and the 1st div, because this will also ruin the layout.
Why can't I bind ngClass to ngContainer and how would I solve my issue?