From c45a27bd01e58f7b30bced226f4b3818c56c9093 Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Tue, 28 May 2024 20:59:18 +0200 Subject: [PATCH] Fix initial annual interest rate --- .../fire-calculator.component.ts | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/libs/ui/src/lib/fire-calculator/fire-calculator.component.ts b/libs/ui/src/lib/fire-calculator/fire-calculator.component.ts index 4f6c8dc08..bd52d8b79 100644 --- a/libs/ui/src/lib/fire-calculator/fire-calculator.component.ts +++ b/libs/ui/src/lib/fire-calculator/fire-calculator.component.ts @@ -123,19 +123,6 @@ export class GfFireCalculatorComponent implements OnChanges, OnDestroy { Tooltip ); - this.calculatorForm.setValue( - { - annualInterestRate: this.annualInterestRate, - paymentPerPeriod: this.savingsRate, - principalInvestmentAmount: 0, - projectedTotalAmount: this.projectedTotalAmount, - retirementDate: this.retirementDate ?? this.DEFAULT_RETIREMENT_DATE - }, - { - emitEvent: false - } - ); - this.calculatorForm.valueChanges .pipe(takeUntil(this.unsubscribeSubject)) .subscribe(() => { @@ -169,9 +156,22 @@ export class GfFireCalculatorComponent implements OnChanges, OnDestroy { } public ngOnChanges() { - this.periodsToRetire = this.getPeriodsToRetire(); - if (isNumber(this.fireWealth) && this.fireWealth >= 0) { + this.calculatorForm.setValue( + { + annualInterestRate: this.annualInterestRate, + paymentPerPeriod: this.savingsRate, + principalInvestmentAmount: 0, + projectedTotalAmount: this.projectedTotalAmount, + retirementDate: this.retirementDate ?? this.DEFAULT_RETIREMENT_DATE + }, + { + emitEvent: false + } + ); + + this.periodsToRetire = this.getPeriodsToRetire(); + setTimeout(() => { // Wait for the chartCanvas this.calculatorForm.patchValue( @@ -409,9 +409,9 @@ export class GfFireCalculatorComponent implements OnChanges, OnDestroy { if (this.projectedTotalAmount) { const periods = this.fireCalculatorService.calculatePeriodsToRetire({ P: this.getP(), - totalAmount: this.projectedTotalAmount, PMT: this.getPMT(), - r: this.getR() + r: this.getR(), + totalAmount: this.projectedTotalAmount }); return periods;