angular - ngbPopover 与从函数返回的 html
问题描述
我有ngbPopover
一个调用来返回我想要填充它的html。我从文档(单击此处)中读到我需要使用模板,如果我将 html 放入其中,那很好,但我想要一个函数来返回 html,但这只是作为字符串出现。
<ng-template #popContent>{{getConnBreakdown(opp)}}</ng-template>
<button type="button" class="btn btn-outline-secondary mr-2" placement="top" [ngbPopover]="popContent" popoverTitle="Connection Types">{{ getTotalConnections(opp) }}</button>
函数看起来像:
getConnBreakdown(opp: IOpportunity){
let returntable = '<table><tbody>';
this.connectonTypes.map(t =>
returntable += '<tr><td>' + t.name + '<td><td>' + opp.products.filter(p => p.connectionTypeId === t.id).reduce((a, b) => { return a + b.quantity; }, 0) + '</td></tr>'
);
returntable += '</tbody></table>';
return returntable;
}
我试过绑定到innerHTML
<ng-template #popContent ng-bind-html="getConnBreakdown(opp)"></ng-template>
但我总是将 html 作为字符串获取。
解决方案
您可以在位于模板中的innerHTML
a中使用,如本答案所示。像这样修改你的:<div>
<ng-template>
<ng-template #popContent>
<div [innerHTML]="getConnBreakdown(opp)"></div>
</ng-template>
这是我修改并得到了这个结果的正在运行的 stackblitz (我还调整了位置以正确显示此示例):
祝你好运!
推荐阅读
- python - 当数据无序时,熊猫从另一个数据框中复制值
- graphql - Absinthe - 如何将_session 放入解析器函数中?
- python - 机器人在重复自己?
- python-3.x - 尝试使用 Celery+RabbitMQ 设置优先级队列时出现“PreconditionFailed - inequivalent arg 'x-max-priority' for queue”错误
- python - 如何根据每个 ID 的第一个和最后一个审查日期列对行进行分组,并使用 python 转发填充 N/A 值?
- swiftui - SwiftUI:ToolbarItem(放置:.principal)中的按钮在更改标签后不起作用
- haskell - 在 Haskell 中使“A || B && C”无点
- haskell - Haskell - 左箭头与嵌套 case 语句
- flutter - Flutter 自定义裁剪器
- javascript - 将数据库值与用户输入相乘