I am using the attribute innerHTML
to edit the inner html of a tag, in this example of <td></td>
, but it could be anything:
<td *matCellDef="let order" mat-cell [innerHTML]="order.statusForInterval | statusIcon"></td>
order.statusForInterval
is a number and as you can see im calling the pipe statusIcon
to return a string which then is binded to innerHTML
. The pipe looks like this:
@Pipe({name: 'statusIcon'})
export class StatusIconPipe implements PipeTransform {
transform(statusId: number) {
switch (statusId) {
case 0:
return `<img class="status-icon" src="assets/svg/status-icon/open_icon.svg" alt="up" matTooltip="Open">`;
case 1:
return `<img class="status-icon" src="assets/svg/status-icon/progress_icon.svg" alt="up" matTooltip="Progress">`;
case 2:
return `<img class="status-icon" src="assets/svg/status-icon/checked_icon.svg" alt="up" matTooltip="Checked">`;
case 3:
return `<img class="status-icon" src="assets/svg/status-icon/booked_icon.svg" alt="up" matTooltip="Booked">`;
case 4:
return `<img class="status-icon" src="assets/svg/status-icon/error_icon.svg" alt="up" matTooltip="Error">`;
}
}
}
So depending on the number i return a string containing an img
tag which then is binded to innerHTML.
All works as expected. The only problem i have is that the tooltips aren´t working when i use the innerHTML
attribute. The attribute matTooltip="Open"
is ignored if i set innerHTML this way.
Is there any way to make the tooltips work using innerHTML
?