Fullcalendar Angular-未应用Tooltip.js CSS(CSS封装问题)

时间:2019-06-15 16:28:21

标签: javascript angular fullcalendar tooltip fullcalendar-4

我已经在Fullcalendar的eventMouseEnterEnter和eventMouseLeave事件上添加了Tooltip.js,但是Tooltip并未设置样式,它仅显示纯文本。请参见下图。

enter image description here 我尝试在此处使用this示例,但没有结果。

如何像下面的示例那样设置工具提示的样式?

enter image description here

这是我的代码:

appointmentment.component.ts

import { Component, ViewChild } from '@angular/core';
import { FullCalendarComponent } from '@fullcalendar/angular';
import { EventInput } from '@fullcalendar/core';
import dayGridPlugin from '@fullcalendar/daygrid';
import timeGrigPlugin from '@fullcalendar/timegrid';
import interactionPlugin from '@fullcalendar/interaction';
import roLocale from '@fullcalendar/core/locales/ro';
import Tooltip from 'tooltip.js'

@Component({
  selector: 'app-appointment',
  templateUrl: './appointment.component.html',
  styleUrls: ['./appointment.component.css']
})

export class AppointmentComponent {
  tooltip: Tooltip;

  @ViewChild('calendar') calendarComponent: FullCalendarComponent; // the #calendar in the template
  calendarLocale = roLocale;
  calendarVisible = true;
  calendarPlugins = [dayGridPlugin, timeGrigPlugin, interactionPlugin];
  calendarWeekends = true;
  calendarEvents: EventInput[] = [
    { title: 'Cod: #123124124', description: "TEXT", start: new Date(), customRender: true },
  ];

  handleEventMouseEnter(info) {
    this.tooltip = new Tooltip(info.el, {
      title: info.event.title,
      placement: 'top'
    });
  }
  handleEventMouseLeave(info) {
    this.tooltip.dispose();
  }
}

appointment.component.html

<app-navbar></app-navbar>
<full-calendar #calendar defaultView="dayGridMonth"
    [header]="{left: 'prev,next today', center: 'title', right: 'dayGridMonth,timeGridWeek,timeGridDay,listWeek'}"
    [plugins]="calendarPlugins" [weekends]="calendarWeekends" [events]="calendarEvents" [locale]="calendarLocale"
    (eventMouseEnter)="handleEventMouseEnter($event)"
    (eventMouseLeave)="handleEventMouseLeave($event)"></full-calendar>

LE :似乎CSS没有应用。我使用了示例中的CSS。

2 个答案:

答案 0 :(得分:1)

默认情况下, title 元素为textElement,并且没有多余的样式。如果要设置工具提示的样式,则必须在构造函数的 options 参数中启用 HTML

  handleEventMouseEnter(info) {
    this.tooltip = new Tooltip(info.el, {
      html: true,
      title: "<b>" + info.event.title + "</b>",
      placement: 'top'
    });
  }

上面的代码应使工具提示文本加粗。 或者,您可以根据需要包装标题HTML样式。

答案 1 :(得分:1)

这是由CSS封装问题引起的。根据{{​​3}}的答案。

添加

@Component({
  selector: 'app-appointment',
  templateUrl: './appointment.component.html',
  styleUrls: ['./appointment.component.css'],
  encapsulation: ViewEncapsulation.None
})

解决了我的问题。