I'm using Angular 14 and neither of the answers worked for me right away.
First I added a class to the mat-tooltip
:
<mat-icon
[matTooltip]="tooltip"
matTooltipClass="tooltip-class"
</mat-icon>
I also needed to add ::ng-deep to the css (sass in my case):
::ng-deep .tooltip-class
white-space: pre-line
The Unicode line break
also didn't work. Since I'm using string template a line break in the .ts
file worked:
const tootltipText = `${strings.method}: ${strings.note}
${strings.reason}: ${strings.snapshot}`
I also tested adding \n
and it works both with regular strings and string tamplates:
const tootltipText = 'line\nbreak\nworks'
` or `