Reputation: 423
//html
<span style="margin-left:43%;background-color:rgb(229,229,229);border-
radius:10%"> {{formatEpoch(epoch)}} </span>
//ts
lastdate:any;
formatEpoch(epoch): string {
if(epoch == this.lastdate){
return '';
}else{
this.lastdate =epoch;
return UtilService.getCalendarDay(epoch);
}
}
ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: '今天 5:34 PM'. Current value: ''.
How can i fix this error? Please help.
Upvotes: 0
Views: 1911
Reputation: 487
the best solution:
import { Platform } from '@ionic/angular';
// ...
constructor(
...
private _platform:Platform
) { }
ngOnInit() {
this._platform.ready().then(() => {
this.formatEpoch()
})
}
Upvotes: 0
Reputation: 3631
if like in angular, try to use
this._changeDetectionRef.detectChanges();
at the end of your method, not forgetting to add
private _changeDetectionRef : ChangeDetectorRef
as parameter of the constructor of the Component owning your method.
See discution here
Upvotes: 1
Reputation: 1026
Could you try this
lastdate:any;
formatEpoch(epoch): string {
setTimeout(()=> {
if(epoch == this.lastdate){
return '';
}else{
this.lastdate =epoch;
return UtilService.getCalendarDay(epoch);
}
}, 100);
}
Upvotes: 0