我正在嘗試在我創建的表中填充多行。該表成功填充,但是出現錯誤:
「ExpressionChangedAfterItHasBeenCheckedError:檢查後表達式已更改。上一個值:'1'。當前值:'ah'。」
這不是一個真正的問題,因爲錯誤不會導致我的程序或任何東西崩潰,但是無論何時我更改表格中的任何單位,它都會將所有單位的值更改爲「當前值」爲在上面的錯誤。 (在這種情況下,我做了「啊,」見下面的代碼)
這是我如何填充表:Angular 2 - ExpressionChangedAfterItHasBeenCheckedError
<div class="row-container">
<div *ngFor="let week of getWeeks()" class="row">
<input class="week" maxlength="2" (input)="type($event.target.value, week)" value="{{getCapacity(week)}}">
</div>
</div>
這就是我如何更新值:
getCapacity(week: Date): string {
if (<conditions are met>) {
const capacity = EntryComponent.capacity[EntryComponent.index];
EntryComponent.index++;
return capacity.value;
}
return 'ah';
}
我沒有使用動態組件作爲標記,而是動態更改輸入標記的值。
我想你可以猜測:你應該已經把價值綁定並改變它。 – Vega
[Angular動態組件加載 - ExpressionChangedAfterItHasBeenCheckedError]可能的副本(https://stackoverflow.com/questions/43917940/angular-dynamic-component-loading-expressionchangedafterithasbeencheckederror) –
在開發模式中,Angular運行每個更改循環兩次,並且錯誤正在發生,因爲它們之間發生了變化(它不應該)。這可能是因爲你的第一個改變循環正在改變你的「條件滿足」條件。 – LarsMonty