我正在使用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
});
}
}
替换事件列表会触发另一个onViewRender事件,从而导致无限循环。
答案 0 :(得分:0)
我刚刚将ngprime从2.0.3降级到2.0.0,现在它运行正常。没有更多api电话。