eventMouseOver fullCalendar Angular 6不起作用

问题描述 投票:1回答:2

我正在使用全日历版本:角度6中的3.6.1并且我想在mouseOver事件时显示popOver当我在component.html中添加(eventMouseOver)时没有任何问题

这是我的calendar.component.ts代码

import {Component, ElementRef, OnInit, ViewChild} from '@angular/core';
import {CalendarComponent} from 'ng-fullcalendar';
import { Options } from 'fullcalendar';
import {CompanyService} from '../company/company.service';
import {Person} from '../person';
import { Event } from '../event';
import {style} from '@angular/animations';
import {validate} from 'codelyzer/walkerFactory/walkerFn';
import {NgbPopoverConfig} from '@ng-bootstrap/ng-bootstrap';
import * as $ from 'jquery';
@Component({
  selector: 'app-calendars',
  templateUrl: './calendars.component.html',
  styleUrls: ['./calendars.component.css']
})
export class CalendarsComponent implements OnInit {

  @ViewChild(CalendarComponent) ucCalendar: CalendarComponent;
  calendarOptions: Options;
  event: Event;
  events = [];
  person: Person;
  persons = [];
  elemChecked = [];
  color;
  idsStr = '';
  eventOut;
  modal = false;
  SelectedEvent: Event;
  selectedPerson: Person;
  constructor(private Service: CompanyService,private config: NgbPopoverConfig, private element: ElementRef) {
    config.placement = 'right';
    config.triggers = 'hover';
  }

  ngOnInit() {
  this.getDataFromServer();
  setTimeout(() => {
    this.createCalendar();
  }, 500);

  }

  getDataFromServer() {
    this.Service.getPerson().subscribe(data => {
      data.forEach((value => {
        this.person = {
          id: value.id,
          name: value.name,
          color: value.color,
          event: ''
        };
        this.persons.push(this.person);
      }));
      data.forEach((value => {
        let length = value.event.length;
        for (let i = 0 ; i < length; i++) {
          this.event = {
            id: value.event[i].id,
            title: value.event[i].title + '-' + value.name,
            start: value.event[i].start,
            end: value.event[i].end,
            color: value.event[i].color,
            person: value.id,
            ngbPopover: 'qsdqsd'
          };
          this.events.push(this.event);
        }
      }));
      this.persons.forEach((value => {
        this.elemChecked.push(value.id);
      }));
    });

  }
  createCalendar() {
    this.calendarOptions = {
      editable: true,
      eventLimit: true,
      header: {
        left: 'prev,next today',
        center: 'title',
        right: 'month,agendaWeek,agendaDay,listMonth'
      },
      selectable: true,
      events: this.events,
      slotEventOverlap: false,
    };
  }

  Color(elem) {
    this.color = null;
    this.persons.forEach((value => {
      if (+value.id === +elem.target.id) {
         this.color = value.color;
      }
    }));
    if (elem.target.checked) {


      elem.target.parentElement.style.background = this.color ;
      this.elemChecked.push(+elem.target.id);
      elem.target.style.marginRight = '500px';

    } else {

      for (let i = 0; i < this.elemChecked.length; i ++) {
        if (+this.elemChecked[i] === +elem.target.id) {
          this.elemChecked.splice(i, 1);
        }
      }
      elem.target.parentElement.style.background = '#DCDCDC';
      console.log('grey');
    }
    this.updateData(this.elemChecked);

  }
  updateData(ids) {
    this.events = [];
    this.idsStr = '';
   ids.forEach( (value => {
     this.idsStr = this.idsStr + value + ';' ;
   }));
   this.Service.getEventsByIds(this.idsStr).subscribe(data => {
     this.events = data;

     data.forEach((value => {
      for (let i = 0; i < value.length; i ++) {
        this.event = {
          id: value[i].id,
          title: value[i].title + '-' + value[i].person.name,
          start: value[i].start,
          end: value[i].end,
          color: value[i].color,
          person: value[i].person.id
        };
        this.events.push(this.event);
        this.ucCalendar.renderEvents(this.events);
      }
     }));
   });


  }
  EventClick(calEvent, jsEvent, view, resourceObj, element) {

    calEvent.target.style.width = '1px';
    this.SelectedEvent = {
      title: calEvent.detail.event.title,
      start: calEvent.detail.event.start,
      end: calEvent.detail.event.end,
      color: calEvent.detail.event.color,
      person: calEvent.detail.event.person
    };
    this.persons.forEach((value => {
      if (value.id === calEvent.detail.event.person) {
        this.selectedPerson = {
          name: value.name
        };
      }
    }));
    this.modal = true;
  }

  closeModal() {
    this.modal = false;
  }
  MouseOver(event) {
  console.log(event);
  }
  EventRender(event) {
   this.ucCalendar.eventMouseOut.emit(console.log('qsdqs'));
  }
}

calendar.component.html

    <div *ngIf="calendarOptions">
  <ng-fullcalendar #ucCalendar [options]="calendarOptions"
                   (eventClick)="click($event)"
                   (eventMouseOver)="MouseOver($event)"
                    ></ng-fullcalendar>
</div>

我知道这是topic的副本,但那里没有答案。

angular fullcalendar mouseover
2个回答
0
投票

你可以捕捉从控制中发出的CustomEvent

HTML

<ng-fullcalendar ... (eventMouseover)="MouseOver($event)"
                                ^
                             lowercased o

component.ts

MouseOver(event) {
  console.log(event.detail);
}

0
投票

您可以在calendarOptions中的fullcalendar的eventMouseover事件中添加处理程序。参数可以在fullcalendar documentation中看到。

例:

createCalendar() {
    this.calendarOptions = {
        editable: true,
        eventLimit: true,
        header: {
            left: 'prev,next today',
            center: 'title',
            right: 'month,agendaWeek,agendaDay,listMonth'
        },
        selectable: true,
        events: this.events,
        slotEventOverlap: false,
        eventMouseover: (event, jsEvent, view) => this.eventMouseOver(event, jsEvent, view)
    };
}


eventMouseOver(event, jsEvent, view) {
    // TODO: Open popover with event data
}
© www.soinside.com 2019 - 2024. All rights reserved.