Home > Blockchain >  typescript new line character in string is not working
typescript new line character in string is not working

Time:12-11

I'm using a directive to show a tooltip text:

<i  [nz-tooltip]='infoBulleContent'  nzTooltipPlacement='topRight'></i>

in ts code, this.infoBulleContent = 'Some text \n some text'; but the \n is not working, i used also the br tag, same result!

any help please

CodePudding user response:

With a quick search elsewhere on SO I found a solution for you to try. Their answer: "\n does not cause a line break in HTML, you will have to use <br/> or wrap your text in a block element."

this.infoBulleContent = 'Some text'   <br/>   'some text' 

CodePudding user response:

This won't work, alas. As you can see in the source of this tooltip component, the title that you give is not parsed but directly included as a string in the template.

Having said that, what you probably want here is to pass a TemplateRef, which allows you to include multiple lines, but also styling (which is preferable over using manual br-line breaks). E.g.

    <!-- Element that should have a tooltip -->
    <button nz-tooltip [nzTooltipTitle]="titleTemplate">Test</button>

    <!-- Contents of tooltip -->
    <ng-template #titleTemplate>
      <p style="font-size: 25px">Your <br> tooltip</p>
    </ng-template>
  • Related