Javascript 如何在具有角度8的FullCalendar中使用gotoDate()
我用的是angular 8,我想输入一个特定的日期。 我搜索了很多,但所有的搜索结果都是针对AngularUI、angularjs、javascript的,我不知道如何在Angular8中使用它。 我不知道如何开始,但我将展示我使用完整日历的方式:Javascript 如何在具有角度8的FullCalendar中使用gotoDate(),javascript,angular,fullcalendar,fullcalendar-4,Javascript,Angular,Fullcalendar,Fullcalendar 4,我用的是angular 8,我想输入一个特定的日期。 我搜索了很多,但所有的搜索结果都是针对AngularUI、angularjs、javascript的,我不知道如何在Angular8中使用它。 我不知道如何开始,但我将展示我使用完整日历的方式: import { FullCalendarComponent } from "@fullcalendar/angular"; import { EventInput, Calendar } from "@fullcalendar/core"; imp
import { FullCalendarComponent } from "@fullcalendar/angular";
import { EventInput, Calendar } from "@fullcalendar/core";
import dayGridPlugin from "@fullcalendar/daygrid";
import timeGrigPlugin from "@fullcalendar/timegrid";
import interactionPlugin from "@fullcalendar/interaction";
import {
MatDialog,
MatDialogRef,
MAT_DIALOG_DATA
} from "@angular/material/dialog";
@Component({
selector: "app-home",
templateUrl: "./home-admin.component.html",
styleUrls: ["./home-admin.component.css"]
})
export class HomeAdminComponent implements OnInit {
@ViewChild("fullcalendar", { static: false })
calendarComponent: FullCalendarComponent;
//storing the events shown in the calendar
calendarEvents: EventInput[] = [];
// using plugins to interact with the calendar
calendarPlugins = [dayGridPlugin, timeGrigPlugin, interactionPlugin];
//getting the calendar api
calendarApi: Calendar;
constructor( public dataholder: DataHolder) {}
ngOnInit() {
this.loadEvents();
}
ngAfterViewChecked() {
this.calendarApi = this.calendarComponent.getApi();
}
//used to load the events of the calendar
loadEvents() {
this.calendarEvents = this.dataholder.calendarEvents; //I get the events from a service and it's working fine
console.log("laodevents", this.calendarEvents);
this.calendarApi.removeAllEventSources();
this.calendarApi.addEventSource(this.calendarEvents);
}
//when clicking the date not the event(the white square)
onDateClick(clickedDate: any) {
let date = clickedDate.date;
console.log("date:", date);
let dialogRef = this.dialog.open(AddEventPopupComponent, {
data: {
date: date
}
});
this.loadEvents();
}
//when clicking the event
onEventClick(clickedEvent: any) {
this.dataholder.changeSelectedEventId(clickedEvent.event.id)
}
//when dragging the event
onEventRender(info: any) {
// console.log('onEventRender', info.event.start,info.event.end );
}
}
在html中:
<full-calendar
#fullcalendar
[plugins]="calendarPlugins"
[editable]="true"
[events]="calendarEvents"
[defaultView]="'dayGridMonth'"
[header]="{
left: 'prev,next today',
center: 'title',
right: ''
}"
[dir]="'ltr'"
[events]="calendarEvents"
(dateClick)="onDateClick($event)"
(eventClick)="onEventClick($event)"
(eventRender)="onEventRender($event)">
请为我提供解决方案或建议不同的方法(如果存在)。谢谢 它使用ADyson评论中提到的
这个.calendarApi.goToDate(“2020-01-24”)
工作。日历。渲染功能:
$('.fc-toolbar-ltr').append('<button type="date-local" class="btn btn-primary" id="date_picker"><i class="fas fa-calendar"></i></button>');
$('#date_picker').datepicker({
language: "pt_BR",
dateFormat: 'yyyy-mm-dd',
pick: function(e) {
var s = new Date(e.date);
alert(s);
calendar.gotoDate(s);
sessionStorage.setItem("datadaagenda", dia);
$('#date_picker').val(dia);
}
$('.fc toolbar ltr')。追加('');
$(“#日期选取器”)。日期选取器({
语言:“pt_BR”,
日期格式:“yyyy-mm-dd”,
选择:功能(e){
var s=新日期(即日期);
警报;
历法。哥多达特(s);
sessionStorage.setItem(“数据议程”,dia);
$('date'u picker').val(直径);
}
这是一种方法,因此您可以使用例如this.calendarApi.goToDate(“2020-01-24”)
,就像您已经使用的其他方法一样,例如this.calendarApi.removeAllEventSources()
等。这似乎是JQuery而不是Angular。