我有一个使用的嵌套组件ngbPopover
and popoverTitle
。将显示的内容将通过@Input()
特性。
问题:如果给定的输入类似于"<b>Some Title</b>"
,我希望将其加粗而不是字面显示。
我尝试按照文档中的描述使用here https://ng-bootstrap.github.io/#/components/popover/examples,但就我而言,无论我绑定什么,都会有标记。我的标记不是预定义的。所以这没有帮助。
import { Component, Input } from "@angular/core";
@Component({
selector: "help-popup",
template: `<span
class="fa fa-question-circle-o btn-outline-info btn-sm"
style="font-size: 18px" triggers="focus:blur"
[placement]="placement"
[ngbPopover]="helpText"
container="body"
[popoverTitle]="helpTitle"></span>`
})
export class HelpPopupComponent {
@Input() placement: string = "top";
@Input() helpText: string = "";
@Input() helpTitle: string = "";
}
我想像这样使用它:
<help-popup helpTitle="<b>Bold Title</b>"
helpText="<u>Underline text</u>"></help-popup>
ng-bootstrap Popover 组件允许在其内容中使用 HTML,但是据我所知文档 https://ng-bootstrap.github.io/#/components/popover/api,不在其标题中:ngbPopover
属性可以是一个模板,popoverTitle
属性只是一个字符串。
这个笨蛋 http://plnkr.co/edit/GKHoYfxZFpy6eKgTXesM?p=preview,改编自 ng-bootstrap 文档,展示了如何显示helpText
作为弹出窗口中的 HTML 内容。在弹出窗口模板中,值helpText
被直接分配给innerHTML
div 元素的属性以避免HTML 转义 https://lishman.io/angular-2-interpolation插值会发生这种情况:
<ng-template #popContent><div [innerHTML]="helpText"></div></ng-template>
并且模板绑定到ngbPopover
元素的属性:
<button ... [popoverTitle]="helpTitle" [ngbPopover]="popContent">
...
</button>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)