Angular 2:在Fullcalender中单击按钮时多次调用服务

时间:2017-08-04 09:04:01

标签: angular typescript fullcalendar

我正在使用fullcalender Fullcalender angular 2, 当我从fullcalender点击上一个或下一个时,每次点击呼叫服务并再次将相同的事件添加到日历。

export class Calender {

    public value: any = 1;
    public modalData: any;
    calendarOptions: any;
    @ViewChild(CalendarComponent) myCalendar: CalendarComponent;

    form: FormGroup;

    constructor(private route: Router, private calenderservice: CalenderService) {

    }

    ngOnInit() {

        this.calendarOptions = {
            height: '1000',
            fixedWeekCount: false,
            header:
            {
                    left: 'prev,next,today',
                    center: 'title',
                    right: 'month,listYear',
                    },
            defaultDate: '2017-01-01',
            editable: true,
            eventLimit: true,
            eventColor: '#ff0000',


            events: (start, end, title, callback) => {
               this.calenderservice.getExamCandidateById(this.value)
                   .subscribe(response => {
                       callback(response),
                       this.modalData = response.Items
                       this.myCalendar.fullCalendar('renderEvents', this.modalData, 'stick')
                       console.log("Cal");
                       console.log(response);
                    });
            }

        };

    } 

请帮助我,如何避免多次校准服务。谢谢

1 个答案:

答案 0 :(得分:2)

根据documentation

通常,一旦日历重新获取其事件源,事件将消失(例如:单击prev / next时)。但是,将stick指定为true将导致事件永久固定到日历。

您不应将'stick'指定为第3个参数,也不能将其设置为显式false

看看这是否适合你?