javascript - Angular 6 fullCalendar Display popover on mouseover 事件
问题描述
我在 Angular 6 应用程序中使用 fullCalendar。我想在将鼠标悬停在这样的事件上时显示全日历弹出框。我想通过我的 ts 文件而不使用 jquery 来实现这一点。这是我的代码。
HTML:
<section class="main-content">
<div *ngIf="calendarOptions">
<ng-fullcalendar #ucCalendar
[options]="calendarOptions"
[(eventsModel)]="events"
(eventClick)="handleClick($event.detail.event.data)"
(eventMouseOver)="mouseOver($event, calendarPopover)">
</ng-fullcalendar>
</div>
</section>
<ng-template #calendarPopover>
<h3>{{toolData .title}}</h3>
</ng-template>
TS 文件:
mouseOver(event, content){
var data = event.detail.event.data;
this.toolData = data;
console.log(this.toolData);
}
类似于这里的帖子
我想让 ng-template 在显示器上打开。我已经尝试过 ngbPopover,但与 ngbModal 不同,ngbPopover 没有一个 open 方法,它可以通过调用它的方法来简单地打开 popover,因为它是一个指令。
如果有人知道使用 fullCalendar popover 方法(没有 jquery)或通过 ng-template 显示的任何解决方案,我们将不胜感激。
解决方案
我将此解决方案用于我的 Angular 10 应用程序,带有 FullCalendar 5.3。库tippy.js 非常易于集成和使用 - https://atomiks.github.io/tippyjs/
不需要额外的工具提示 html 元素。只需使用 fullcalendar eventDidMount 渲染钩子为您的事件添加一个提示工具提示:
import tippy from "tippy.js";
...
ngAfterViewInit() {
// create calendar and configure it
eventDidMount: (info) => {
tippy(info.el, {
content: 'Content to display inside tooltip',
})
}
}
如果您想在工具提示中显示动态内容,例如,可以使用以下方法将其设置为事件的标题
eventDidMount: (info) => {
tippy(info.el, {
content: info.event.title,
})
}
}
不再需要代码。工具提示会在悬停时添加到您的事件中。如果要调整工具提示的样式,可以使用 .tippy-box 类。例如,我将其更改为主要匹配 Angular Material 的 Mat-Tooltip。刚刚将样式添加到我的组件的 .css 文件中。
.tippy-box {
color: #fff;
border-radius: 4px;
padding: 3px;
overflow: hidden;
text-overflow: ellipsis;
background: rgba(97, 97, 97, .9);
font-family: Roboto, sans-serif;
font-size: 1rem;
}
推荐阅读
- r - R:如何编写一个函数,根据指定的第三个变量的值创建两个变量的散点图
- compression - 压缩图像
- xml - 使用 Notepad++ 在 XSD 验证中出现错误
- swift - 如何在 UICollectionViewController 中触发 UICollectionViewCell 的功能?
- javascript - Chrome 扩展错误 Unchecked runtime.lastError: 无法建立连接。接收端不存在
- asp.net-core - 将 int 呈现为枚举而不是创建枚举类型招摇
- android - Android Mapbox Navigation - 当用户在同一位置时,有时不会初始化,有时会崩溃
- php - 使用 PHP_EOL 在 txt 文件中写入数据时如何摆脱空间
- android - 在 64 位版本的 Lubuntu 上安装 Android Studio 无法安装一些 32 位库
- javascript - 设置 chrome 代理设置表单扩展