Fix component initialization.

This commit is contained in:
Alexis Lahouze 2018-06-14 11:34:04 +02:00
parent 0e001cf680
commit 1859efb98c
1 changed files with 21 additions and 24 deletions

View File

@ -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();
}
/*