fixed an issue where the pagination would always open on the first page if you went to the URL of a different page

This commit is contained in:
Art Lowel
2017-06-22 18:34:39 +02:00
parent de7300691c
commit f57c0a4fac
4 changed files with 36 additions and 28 deletions

View File

@@ -9,6 +9,7 @@ import {
ViewEncapsulation
} from '@angular/core'
import { ActivatedRoute, Router } from '@angular/router';
import { Subscription } from "rxjs/Subscription";
import { isNumeric } from "rxjs/util/isNumeric";
import 'rxjs/add/operator/switchMap';
import { Observable } from "rxjs";
@@ -139,13 +140,13 @@ export class PaginationComponent implements OnDestroy, OnInit {
*/
public paginationControls;
/**
* Array to track all subscriptions and unsubscribe them onDestroy
* @type {Array}
*/
private subs: Subscription[] = [];
/**
* Subscriber to observable.
*/
private routeSubscription: any;
/**
/**
* An object that represents pagination details of the current viewed page
*/
public showingDetail: any = {
@@ -153,19 +154,14 @@ export class PaginationComponent implements OnDestroy, OnInit {
total: null
};
/**
* Subscriber to observable.
*/
private stateSubscription: any;
/**
* Method provided by Angular. Invoked after the constructor.
*/
ngOnInit() {
this.stateSubscription = this.hostWindowService.isXs()
this.subs.push(this.hostWindowService.isXs()
.subscribe((status: boolean) => {
this.isXs = status;
});
}));
this.checkConfig(this.paginationOptions);
this.id = this.paginationOptions.id || null;
this.currentPage = this.paginationOptions.currentPage;
@@ -173,7 +169,7 @@ export class PaginationComponent implements OnDestroy, OnInit {
this.pageSizeOptions = this.paginationOptions.pageSizeOptions;
this.sortDirection = this.sortOptions.direction;
this.sortField = this.sortOptions.field;
this.routeSubscription = this.route.queryParams
this.subs.push(this.route.queryParams
.filter(queryParams => hasValue(queryParams))
.subscribe(queryParams => {
this.currentQueryParams = queryParams;
@@ -185,7 +181,7 @@ export class PaginationComponent implements OnDestroy, OnInit {
) {
this.validateParams(queryParams['page'], queryParams['pageSize'], queryParams['sortDirection'], queryParams['sortField']);
}
});
}));
this.setShowingDetail();
}
@@ -193,8 +189,9 @@ export class PaginationComponent implements OnDestroy, OnInit {
* Method provided by Angular. Invoked when the instance is destroyed.
*/
ngOnDestroy() {
this.stateSubscription.unsubscribe();
this.routeSubscription.unsubscribe();
this.subs
.filter(sub => hasValue(sub))
.forEach(sub => sub.unsubscribe());
}
/**