// HTML離子如何修復「ExpressionChangedAfterItHasBeenCheckedError」的錯誤?
<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:它檢查後表達發生了變化。上一個值:'今天5:34 PM'。當前值: ''。
我怎麼能解決這個錯誤?請幫忙。
從模板刪除與副作用表達 – yurzui
感謝答覆。你想告訴更多細節嗎? – fastworker399
Angular在開發模式下運行兩個更改檢測週期。在第一次檢查你改變'this.lastdata'所以第二次檢查拋出錯誤 – yurzui