目前,我在延迟加载事件时遇到异常。我跟着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]
PrimeNG 5.2.3,Angular 5.2.4
答案 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