PAR
PAR

Reputation: 441

Angular 2 : Multiple call to service when click buttons in Fullcalender

I am using fullcalender Fullcalender angular 2, when i click prev or next from fullcalender, every click calling service and adding same event one more time to a calender.

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);
                    });
            }
         
        };
       
    } 

Please help me,how to avoid multiple cal to service.thanks

Upvotes: 0

Views: 464

Answers (1)

Rutvik Bhatt
Rutvik Bhatt

Reputation: 486

As per the documentation:

Normally, the event will disappear once the calendar refetches its event sources (example: when prev/next is clicked). However, specifying stick as true will cause the event to be permanently fixed to the calendar.

You should not specify 'stick' as a 3rd argument or you can set it to explicitly false.

See if this works for you or not?

Upvotes: 2

Related Questions