Я получаю следующую ошибку, указанную ниже.Я провел некоторое исследование, и люди сказали, чтобы положить его в ngoninit или ngAfterViewInit, но это не сработало, так что, может, кто-нибудь, пожалуйста, помогите мне, как я могу это исправить.Соответствующий код приведен ниже.
TrialBalanceComponent.html:29 ERROR Error: ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: 'undefined: 374208'. Current value: 'undefined: 748416'.
at viewDebugError (core.js:7393)
at expressionChangedAfterItHasBeenCheckedError (core.js:7381)
at checkBindingNoChanges (core.js:7483)
at checkNoChangesNodeInline (core.js:10346)
at checkNoChangesNode (core.js:10333)
at debugCheckNoChangesNode (core.js:10936)
at debugCheckRenderNodeFn (core.js:10890)
at Object.eval [as updateRenderer] (TrialBalanceComponent.html:29)
at Object.debugUpdateRenderer [as updateRenderer] (core.js:10879)
at checkNoChangesView (core.js:10234)
HTML-код:
<td>{{totalDebits() | number:'1.2'}}</td>
<td>{{totalcredits() | number:'1.2'}}</td>
ts-код:
totalDebits() {
let totalDebit = 0;
this.accountList.forEach((account) => {
if (account.accountType === 'debit') {
this.totalDebitBalance.push(account.accountBalance);
}
});
this.totalDebitBalance.forEach((amount) => {
totalDebit = totalDebit + amount;
});
return totalDebit;
}
totalcredits() {
let totalCredit = 0;
this.accountList.forEach((account) => {
if (account.accountType !== 'credit') {
this.totalCreditBalance.push(account.accountBalance);
}
});
this.totalCreditBalance.forEach((amount) => {
totalCredit = totalCredit + amount;
});
return totalCredit;
}
ниже я помещаю код в ng на initно затем я получаю значение 0 из вызова html.
<td><b>${{totalDebitAmount | number:'1.2'}} </b></td>
<td><b>${{totalCreditAmount | number:'1.2'}}</b></td>
ts code
ngOnInit() {
this.totalDebits();
this.totalcredits();
}
totalDebits() {
let totalDebit = 0;
this.accountList.forEach((account) => {
if (account.accountType === 'debit') {
this.totalDebitBalance.push(account.accountBalance);
}
});
this.totalDebitBalance.forEach((amount) => {
totalDebit = totalDebit + amount;
});
this.totalDebitAmount = totalDebit;
// return totalDebit;
}
totalcredits() {
let totalCredit = 0;
this.accountList.forEach((account) => {
if (account.accountType !== 'credit') {
this.totalCreditBalance.push(account.accountBalance);
}
});
this.totalCreditBalance.forEach((amount) => {
totalCredit = totalCredit + amount;
});
this.totalCreditAmount = totalCredit;
// return totalCredit;
}