代码之家  ›  专栏  ›  技术社区  ›  user8819437

onViewRender和在完整日历中加载事件的事件之间的差异

  •  0
  • user8819437  · 技术社区  · 8 年前

    我使用onViewRender在angular2应用程序中加载整个日历的事件。使用onViewRender进行多个api调用以获取事件。我可以在模板中使用onViewRender以外的任何东西来加载事件吗。下面是我面临的问题。

    Put a <p-schedule (onViewRender)="testMethod($event)"> on your template. Add a method such as this to your component:
    
    testMethod(e)
    {
    console.log(e);
    }
    
    You'll see that the method is called infinitely.
    

    下面是我的实际代码

    组成部分html

         <p-schedule [events]="events" [eventLimit] ="3" (onViewRender)="loadEvents($event)" 
        (onEventClick)="handleEventClick($event)" 
         (onDayClick)="handleDayClick($event)" ></p-schedule>
    
    component.ts
    
     loadEvents(e) {
    
    
        if (this) {
          let month = e.view.start._d.getMonth() + 2;
          let year = e.view.start._d.getFullYear();
    
          if (month == '13') {
            month = 1;
            year = year + 1;
    
          }
    
          this.userService.getGadgetsData(this.calendarInfo.id, "Calendar", month, year).subscribe(gadgetsData => {
    
    
             this.newEvents = gadgetsData.Data.Issues.map(function (o) {
              return o.Values.reduce(function (acc, _ref) {
                var Key = _ref.Key,
                  Value = _ref.Value;
                return acc[Key] = Value, acc;
              }, {});
            });
    
            this.newEventsInfo = JSON.parse(JSON.stringify(this.newEvents).split(this.eventField).join('eventDate'));
    
            this.calendarEvents = this.newEventsInfo.map(({ Key, Summary, eventDate, Created }) =>
              ({ title: Key + ': ' + Summary, start: eventDate, id: Key, tooltip: Summary }));
    
            this.eventsData = this.calendarEvents.map(function (o) {
    
              o.start = moment.utc(o.start).format('YYYY-MM-DD');
              return o;
    
            });
    
             this.events = this.eventsData; // here is the code which replaces event list
    
          });
        }
    
      }
    

    替换事件列表会触发另一个onViewRender事件,导致无限循环。

    1 回复  |  直到 8 年前
        1
  •  0
  •   user8819437    8 年前

    我刚刚把ngprime从2.0.3降到了2.0.0,现在它运行良好。不再调用api。