简体   繁体   English

在 matToolTip (Angular) 中渲染 html 内容

[英]Rendering html content in matToolTip (Angular)

I want to bold some contents in the popup.我想在弹出窗口中加粗一些内容。 But is not interpreted instead is being displayed among the content但不是被解释而是被显示在内容中

Is there any other way, leaving matToolTip to provide popup over hover in Angular有没有其他方法,让 matToolTip 提供在 Angular 中悬停的弹出窗口

 <button [matTooltip]="help|translate"  type="button"  mat-button class="button-save" [disabled]="!isInfoAvailable">
          <mat-icon>help_outline</mat-icon>
        </button>

Expected output预期输出

firstname mike名字迈克

lastname ross姓氏罗斯

Actual output实际产量

<b>firstname <\b> mike <\n>
<b>lastname <\b> ross

I think native Angular Material Tooltips don't allow HTML code, so I suggest you to use an other provider for the Tooltips, there are a lot of those who allows HTML code like ng-bootstrap or tippy.js我认为原生 Angular Material Tooltips 不允许使用 HTML 代码,所以我建议您使用其他工具提示提供者,有很多允许使用 HTML 代码的工具提示,例如 ng-bootstrap 或 tippy.js

I personally suggest you to use Tippy.js, here's the link where you can see how use HTML code on it.我个人建议您使用 Tippy.js,这是您可以查看如何在其上使用 HTML 代码的链接。

https://atomiks.github.io/tippyjs/#html-content https://atomiks.github.io/tippyjs/#html-content

Hope it helps you.希望对你有帮助。

If you need simple customization (changing background-color, color, font-size...) for the whole tooltip you can read this post otherwise you can read this answer ⬇️如果您需要对整个工具提示进行简单的自定义(更改背景颜色、颜色、字体大小...),您可以阅读这篇文章,否则您可以阅读此答案⬇️


A similar post already exists: Angular 2 Material tooltip with HTML content in angular一个类似的帖子已经存在: Angular 2 Material tooltip with HTML content in angular

What you are looking for is a Popover .您正在寻找的是Popover And as said, it doesn't exist now and it's not possible with tooltips.如前所述,它现在不存在,工具提示也不可能。

Answer from @jelbourn , Angular member team: Angular 成员团队@jelbourn 的回答:

When designing the tooltip we deliberately decided not to support this.在设计工具提示时,我们故意决定不支持这一点。 The Material Design spec is rather prescriptive about only text appearing in tooltips. Material Design 规范对仅出现在工具提示中的文本有相当的规定。 Rich content also presents a challenge for a11y.丰富的内容也给 a11y 带来了挑战。

Source: https://github.com/angular/components/issues/5440#issuecomment-313740211来源: https : //github.com/angular/components/issues/5440#issuecomment-313740211

You can find the feature request for popover here .您可以在此处找到 popover 的功能请求。


Until an official release from Material team you can use an alternative.在 Material 团队正式发布之前,您可以使用替代方案。 Here are some examples:这里有些例子:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM