ng-fullcalendar - Angular 6 - external events in ngFor loop

一世执手 提交于 2019-12-25 03:32:51

问题


I try to use "drag and drop" function with external events.

It works except if I use *ngFor :

My HTML file :

<p>Interventions en attente</p>
<ul id='external-events'>
     <li *ngFor="let ticket of ticketList">
        <div class='fc-event'>{{ ticket.message }}</div>  // Doesn't Work !!
     </li>
     <li>
         <div class='fc-event'>My Event 1</div>  // Works !!
     </li>
</ul>

Here my TS file :

ngAfterViewInit() {
    $('#external-events .fc-event').each(function () {
        // store data so the calendar knows to render an event upon drop
        $(this).data('event', {
            title: $.trim($(this).text()), // use the element's text as the event title
            stick: true // maintain when user navigates (see docs on the renderEvent method)
        });
        // make the event draggable using jQuery UI
        $(this).draggable({
            zIndex: 999,
            revert: true,      // will cause the event to go back to its
            revertDuration: 0  //  original position after the drag
        });

    });
}

How can I solve that ?

**************** UPDATE 2 ***********************

Here is my new getTickets method by following advices in comment :

 getNewTickets() {
    this.loading = false;
    this.myJarviaServices.getNewTickets()
        .subscribe(resp => {
                console.log('angular');
            this.ticketList = resp.content;
            console.log(this.ticketList);
                this.customevents.forEach(function (item) {
                    // store data so the calendar knows to render an event upon drop
                    $(item.nativeElement).data('event', {
                        title: $.trim($(item.nativeElement).text()), // use the element's text as the event title
                        stick: true // maintain when user navigates (see docs on the renderEvent method)
                    });
                    // make the event draggable using jQuery UI
                    $(item.nativeElement).draggable({
                        zIndex: 999,
                        revert: true,      // will cause the event to go back to its
                        revertDuration: 0  //  original position after the drag
                    });

                });
        },
        error => {
            console.log('authService.login error' + error);
            console.log('error status : ' + error.status);
            // this.alertService.error(error);
            this.myJarviaServices.error(error);
        });
}

I have no error message but it doesn't work


回答1:


Here is the angular version code.

<p>Interventions en attente</p>
<ul id='external-events'>
     <li #customevents *ngFor="let ticket of ticketList">
        <div class='fc-event'>{{ ticket.message }}</div>  // Doesn't Work !!
     </li>
</ul>

Component:

@ViewChildren('customevents') customevents: QueryList<any>;
ngAfterViewInit() {
   setTimeout(()=>{
   this.customevents.forEach(function (item) {
        // store data so the calendar knows to render an event upon drop
        $(item.nativeElement).data('event', {
            title: $.trim($(item.nativeElement).text()), // use the element's text as the event title
            stick: true // maintain when user navigates (see docs on the renderEvent method)
        });
        // make the event draggable using jQuery UI
        $(item.nativeElement).draggable({
            zIndex: 999,
            revert: true,      // will cause the event to go back to its
            revertDuration: 0  //  original position after the drag
        });

    });
 }, 100);
}


来源:https://stackoverflow.com/questions/53611774/ng-fullcalendar-angular-6-external-events-in-ngfor-loop

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!