0

Im using Angular 7 and Angular material matTooltip.

I want that the tooltip displays every element in the next line, something like this:

enter image description here

But, instead I'm getting this:

enter image description here

I got 3 elements per line, and I don't want that. I want one element/line.

My code is as follows:

app.component.ts

items=['15-09-2020: 200','16-09-2020: 200','17-09-2020: 200', '18-09-2020: 200'];
newItems = this.items.join("\r\n");

app.component.html

<div class="col col-sm-2" matTooltipPosition="after" matTooltip="{{ items}}"></div>

Check this example that is not working for me:

Stackbliz

Amos Isaila
  • 286
  • 3
  • 14

3 Answers3

0

Source : https://www.angularjswiki.com/material/tooltip/

It's a bit late, to people who want to have breaklines in the tooltip, you create a custom class in your global CSS and add this class with "matTooltipClass".

HTML

<button mat-raised-button
    matTooltip="Multiline Tooltip &#13; This is second line"
    matTooltipClass="multiline-tooltip">
    Multiline tooltip
</button>

Global CSS

.multiline-tooltip{
  white-space: pre-line;
}

You can also add in your specific component, you should add

encapsulation: ViewEncapsulation.None

to your component.ts

@Component({
  selector: 'app-tooltip',
  templateUrl: './tooltip.component.html',
  styleUrls: ['./tooltip.component.scss'],
  encapsulation: ViewEncapsulation.None
})
export class TooltipComponent implements OnInit {

  constructor() { }

  ngOnInit() {
  }

}

https://siderite.dev/blog/styling-angular-material-tooltips.html/

Hope this can help others

Sigvent
  • 297
  • 4
  • 17
0

The answer from Asaf is working perfectly for me. Angular 14

matTooltip="Component: Test &#13;&#10;Last updated date: 2023-01-17T09:17:02.753Z"

Mattooltip

Myms
  • 11
  • 2
-1

I have fixed this in my project using &#13;&#10;

So, what you'll need to do is:

newItems = this.items.join("&#13;&#10;");

Another thing, you need to change this:

matTooltip="{{ items}}"

To this:

[matTooltip]="items"
Asaf
  • 1,446
  • 9
  • 17