我正在设置primeNG日历,想知道如何在编辑时显示保存的日期。
<p-calendar name="startDate" [(ngModel)]="classPrg.startDate"> </p-calendar>
<p-calendar name="endDate" [(ngModel)]="classPrg.endDate"></p-calendar>
ngOnInit() {
this.classPrg = this.classPrgStore.state.entry.data;
if (!this.classPrg) {
let id: string = this.activedRoute.snapshot.params['id'];
if (await this.classPrgStore.loadClassPrg(id).toPromise()) {
this.classPrg = this.classPrgStore.state.entry.data;
this.classPrg.startDate = new Date(this.classPrg.startDate);
this.classPrg.endDate = new Date(this.classPrg.endDate);
}
}
}
答案 0 :(得分:0)
此错误警告您承诺中发生了错误,但是没有处理程序。
由于您将async/await
用于承诺,因此需要catch
块:
ngOnInit() {
this.classPrg = this.classPrgStore.state.entry.data;
if (!this.classPrg) {
let id: string = this.activedRoute.snapshot.params['id'];
try {
if (await this.classPrgStore.loadClassPrg(id).toPromise()) {
this.classPrg = this.classPrgStore.state.entry.data;
this.classPrg.startDate = new Date(this.classPrg.startDate);
this.classPrg.endDate = new Date(this.classPrg.endDate);
}
} catch (error) {
// Handle error, or just leave blank to ignore error
}
}
}