延迟加载时,PrimeNG Schedule会抛出ExpressionChangedAfterItHasBeenCheckedError

时间:2018-04-17 08:09:47

标签: angular fullcalendar primeng

目前,我在延迟加载事件时遇到异常。我跟着PrimeNG doc

异常

AppComponent.html:4 ERROR Error: ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: 'undefined'. Current value: '[object Object],[object Object],[object Object],[object Object],[object Object]'.
at viewDebugError (VM29065 core.umd.js:9794) [angular]

Plunkr

PrimeNG 5.2.3,Angular 5.2.4

1 个答案:

答案 0 :(得分:1)

您可以使用ChangeDetectorRef手动触发组件中的更改检测,以解决您的问题。

constructor(private cdr: ChangeDetectorRef) {
}

并在添加活动后调用detectChanges方法

this.cdr.detectChanges();

修改

为什么不在ngOnInit方法中加载事件?

HTML

<p-schedule [events]="events"></p-schedule>

TS

ngOnInit() {
    this.events = [
            {
                "title": "All Day Event",
                "start": "2018-04-19"
            },
            {
                "title": "Long Event",
                "start": "2018-04-07",
                "end": "2018-04-10"
            },
            {
                "title": "Repeating Event",
                "start": "2018-04-09T16:00:00"
            },
            {
                "title": "Repeating Event",
                "start": "2018-04-16T16:00:00"
            },
            {
                "title": "Conference",
                "start": "2018-04-11",
                "end": "2018-04-13"
            }
        ];
  }

请参阅Plunker