From 89c1c4f64cdc079c99649f2d346f9db45a79f568 Mon Sep 17 00:00:00 2001 From: Alexis Lahouze Date: Sun, 10 Jun 2018 17:50:30 +0200 Subject: [PATCH] Simplify loading using parameter instead of injected account object. --- src/operations/balanceChart.component.ts | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/operations/balanceChart.component.ts b/src/operations/balanceChart.component.ts index b49f578..c860d7e 100644 --- a/src/operations/balanceChart.component.ts +++ b/src/operations/balanceChart.component.ts @@ -5,7 +5,7 @@ import * as moment from 'moment'; import { Component, Inject, Input, Output, EventEmitter, - OnChanges + OnInit, OnChanges } from '@angular/core'; import { ActivatedRoute, Router } from '@angular/router'; @@ -36,7 +36,7 @@ class DateRange { ` }) -export class BalanceChartComponent implements OnChanges { +export class BalanceChartComponent implements OnInit, OnChanges { @Input() account: Account; @Output() onUpdate: EventEmitter = new EventEmitter(); @@ -133,9 +133,11 @@ export class BalanceChartComponent implements OnChanges { this.data = []; } - loadData(account: Account) { + loadData() { + let accountId = this.activatedRoute.snapshot.paramMap.get('accountId'); + this.dailyBalanceService.query( - account.id + +accountId ).subscribe((results) => { this.data = results; @@ -157,12 +159,13 @@ export class BalanceChartComponent implements OnChanges { } } + ngOnInit() { + this.loadData(); + } + ngOnChanges(changes) { if('account' in changes && changes.account.currentValue) { - this.loadData(changes.account.currentValue); this.setLines(changes.account.currentValue); - } else { - this.setLines(this.account); } }