From c844548d68517452acc67006cca5eb36b1cc3a55 Mon Sep 17 00:00:00 2001 From: geek Date: Mon, 11 Jun 2018 12:27:25 +0900 Subject: [PATCH] ing --- .../target/component/list/list.component.ts | 41 ++++++++++--------- .../targets/target-list-page.component.ts | 18 ++++++-- 2 files changed, 36 insertions(+), 23 deletions(-) diff --git a/@overflow/target/component/list/list.component.ts b/@overflow/target/component/list/list.component.ts index d3f0acf..63f8149 100644 --- a/@overflow/target/component/list/list.component.ts +++ b/@overflow/target/component/list/list.component.ts @@ -50,32 +50,33 @@ export class ListComponent implements OnInit, OnChanges { } ngOnInit() { + this.getTargetList(); + } + + ngOnChanges(changes: SimpleChanges): void { + console.log(changes); + if (changes['pageIdx'] && this.paginator) { + console.log(this.pageIdx); + this.getTargetList(); + this.paginator.changePage(this.pageIdx); + } + } + + private getTargetList() { + // console.log('----------------------------------------------------------------'); + // console.log(this.pageIdx); + // console.log('----------------------------------------------------------------'); + + if (this.pageIdx <= 0 || this.pageIdx === undefined || this.pageIdx === null || isNaN(this.pageIdx)) { + this.pageIdx = 0; + } const pageParams: PageParams = { - pageNo: 0, + pageNo: this.pageIdx, countPerPage: 2, sortCol: 'id', sortDirection: 'descending', }; - this.getTargetList(pageParams); - } - - ngOnChanges(changes: SimpleChanges): void { - if (changes['pageIdx'] && this.paginator) { - const pageParams: PageParams = { - pageNo: this.pageIdx, - countPerPage: 2, - sortCol: 'id', - sortDirection: 'descending', - }; - console.log(this.pageIdx); - this.paginator.changePage(this.pageIdx); - this.getTargetList(pageParams); - } - } - - private getTargetList(pageParams: PageParams) { - this.targetService.readAllByProbeID(this.probeID, pageParams) .pipe( tap(() => { diff --git a/src/app/pages/targets/target-list-page.component.ts b/src/app/pages/targets/target-list-page.component.ts index e4bc7fd..f9c57de 100644 --- a/src/app/pages/targets/target-list-page.component.ts +++ b/src/app/pages/targets/target-list-page.component.ts @@ -12,15 +12,27 @@ export class TargetListPageComponent implements OnInit { constructor( private router: Router, - private route: ActivatedRoute + private activatedRoute: ActivatedRoute ) { } ngOnInit() { + this.activatedRoute.queryParams.subscribe(queryParams => { + this.pageIdx = Number(queryParams['page']); + if (this.pageIdx <= 0 || this.pageIdx === undefined || this.pageIdx === null) { + this.pageIdx = 0; + } + // console.log('*****************************************************'); + // console.log(this.pageIdx); + // console.log('*****************************************************'); + }); + // this.pageIdx = this.activatedRoute.snapshot.queryParams['page'] || 1; } onPageChange(pageNo: number) { - this.pageIdx = pageNo + 1; - this.router.navigate(['/probe', this.probeID, 'target'], { queryParams: { page: pageNo + 1 } }); + // console.log('**********************pageNo*******************************'); + // console.log(pageNo); + // console.log('**********************pageNo*******************************'); + this.router.navigate(['/probe', this.probeID, 'target'], { queryParams: { page: pageNo } }); } }