html - Angular 指令 - 动态创建组件和包装内容
问题描述
我想要的是:
简约的工具提示,实际上有效 - 看着你 PrimeNG
我有的:
import {Component, Input} from '@angular/core';
@Component({
selector: 'lib-tooltip',
template: '<div class="tooltip-parent">
<ng-content></ng-content>
<div class="tooltip">
{{label}}
</div>
</div>',
styles: ['
.tooltip-parent {
position: relative;
.tooltip {
display: none;
position: absolute;
font-size: smaller;
z-index: 1014;
background: rgb(73, 80, 87, 0.8);
color: #ffffff;
padding: 0.5rem 0.5rem;
box-shadow: 0 2px 4px -1px rgba(0, 0, 0, 0.2), 0 4px 5px 0 rgba(0, 0, 0, 0.14), 0 1px 10px 0 rgba(0, 0, 0, 0.12);
border-radius: 3px;
}
&:hover {
.tooltip {
display: block;
}
}
}
'],
})
export class TooltipComponent {
@Input() label: string;
}
我可以这样使用:
<lib-tooltip label="this as tooltip">
<li>Should have tooltip</li>
</lib-tooltip>
接下来是什么?
我想要一个指令,即。<li customtooltip [tooltiplabel]="this as tooltip">Should have tooltip</li>
动态生成工具提示组件(ViewContainerRef.createComponent() 或者可能是 createEmbeddedView??) - 我知道如何设置两者,但我无法将任何 html 内容(无论我希望我的工具提示应用于什么)到我的 ng - 内容出口
<div class="tooltip-parent">
<ng-content></ng-content> <---------
<div class="tooltip">
{{label}}
</div>
</div>
解决方案
推荐阅读
- javascript - 始终按照数据集顺序显示自动完成元素
- sql - 加入返回意外的空结果
- json - Kotlin:将嵌套的 JSON 对象转换为文字字符串
- jquery - 为什么在条件语句变为假后第二次按下按钮?
- node.js - 如何将图像从快速服务器导入客户端(在 React 中)
- mysql - MySQL 5.7.24 COUNT() 不能与 sql_mode=only_full_group_by 一起正常工作
- amazon-web-services - 无法从 tinkerpop 连接到海王星数据库实例
- git - 如何处理 git flow 中未合并功能的未来工作?
- c - 在 C 中,为什么当幂设置为 1/2 时,幂函数返回 1?
- c++ - 对类构造函数 h 文件的未定义引用