我正在使用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.
及以下是我的实际代码
component.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
});
}
}
替换事件列表触发了另一个viewrender事件,导致无限循环。
我刚刚将NGPRIME从2.0.3降至2.0.0,现在正常工作。没有更多的API调用。