From 1859efb98c6a4e8f5c5ce3063b6b9e438065b91f Mon Sep 17 00:00:00 2001 From: Alexis Lahouze Date: Thu, 14 Jun 2018 11:34:04 +0200 Subject: [PATCH] Fix component initialization. --- src/operations/operationList.component.ts | 45 +++++++++++------------ 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/src/operations/operationList.component.ts b/src/operations/operationList.component.ts index bb94441..43a535e 100644 --- a/src/operations/operationList.component.ts +++ b/src/operations/operationList.component.ts @@ -3,7 +3,7 @@ import * as moment from 'moment'; import { Component, OnInit } from '@angular/core'; -import { ActivatedRoute, Router } from '@angular/router'; +import { ActivatedRoute, Router, Params } from '@angular/router'; import { Observable } from 'rxjs/Rx'; @@ -80,31 +80,28 @@ export class OperationListComponent implements OnInit { ) {} ngOnInit() { - this.route.queryParamMap.subscribe(() => { - this.loadData(); - }); - - let accountId = this.route.snapshot.paramMap.get('accountId'); - let fromDay = this.route.snapshot.queryParamMap.get('from'); - let toDay = this.route.snapshot.queryParamMap.get('to'); - - if(! fromDay && ! toDay) { - this.router.navigate([], { - queryParams: { - from: moment().startOf('month').format('YYYY-MM-DD'), - to: moment().endOf('month').format('YYYY-MM-DD') - } - }).then(() => { + this.route.queryParamMap.subscribe((params: Params) => { + if (params.get('from') && params.get('to')) { this.loadData(); - }); - } - - this.accountService.get( - +accountId - ).subscribe(account => { - this.account = account; + } else { + this.router.navigate([], { + queryParams: { + from: moment().startOf('month').format('YYYY-MM-DD'), + to: moment().endOf('month').format('YYYY-MM-DD') + } + }); + } + }); + + this.route.paramMap.subscribe((params: Params) => { + let accountId = params.get('accountId'); + + this.accountService.get( + +accountId + ).subscribe(account => { + this.account = account; + }); }); - //this.loadData(); } /*