Skip to content

Commit

Permalink
fix(pagination): and pager to mark for check when page is changed (#2942
Browse files Browse the repository at this point in the history
)
  • Loading branch information
valorkin authored Nov 2, 2017
1 parent 1d18dbb commit e225da7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
8 changes: 4 additions & 4 deletions demo/src/app/components/+pagination/demos/basic/basic.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Component } from '@angular/core';
import { Component, Input } from '@angular/core';

@Component({
selector: 'demo-pagination-basic',
templateUrl: './basic.html'
})
export class DemoPaginationBasicComponent {
totalItems: number = 64;
currentPage: number = 4;
smallnumPages: number = 0;
totalItems = 64;
currentPage = 4;
smallnumPages = 0;

setPage(pageNo: number): void {
this.currentPage = pageNo;
Expand Down
13 changes: 6 additions & 7 deletions src/pagination/pager.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
Input,
Output,
EventEmitter,
forwardRef
forwardRef, ChangeDetectorRef
} from '@angular/core';
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
import { PageChangedEvent } from './pagination.component';
Expand Down Expand Up @@ -97,6 +97,7 @@ export class PagerComponent implements ControlValueAccessor, OnInit {
set page(value: number) {
const _previous = this._page;
this._page = value > this.totalPages ? this.totalPages : value || 1;
this.changeDetection.markForCheck();

if (_previous === this._page || typeof _previous === 'undefined') {
return;
Expand All @@ -115,9 +116,6 @@ export class PagerComponent implements ControlValueAccessor, OnInit {
onChange: any = Function.prototype;
onTouched: any = Function.prototype;

renderer: Renderer2;
elementRef: ElementRef;

classMap: string;
pages: any[];

Expand All @@ -127,9 +125,10 @@ export class PagerComponent implements ControlValueAccessor, OnInit {
protected inited = false;
protected _page = 1;

constructor(renderer: Renderer2,
elementRef: ElementRef,
paginationConfig: PaginationConfig) {
constructor(private renderer: Renderer2,
private elementRef: ElementRef,
paginationConfig: PaginationConfig,
private changeDetection: ChangeDetectorRef) {
this.renderer = renderer;
this.elementRef = elementRef;
if (!this.config) {
Expand Down
13 changes: 7 additions & 6 deletions src/pagination/pagination.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
OnInit,
Output,
Renderer2,
forwardRef
forwardRef, ChangeDetectorRef
} from '@angular/core';
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';

Expand Down Expand Up @@ -102,6 +102,7 @@ export class PaginationComponent implements ControlValueAccessor, OnInit {
set page(value: number) {
const _previous = this._page;
this._page = value > this.totalPages ? this.totalPages : value || 1;
this.changeDetection.markForCheck();

if (_previous === this._page || typeof _previous === 'undefined') {
return;
Expand All @@ -119,8 +120,7 @@ export class PaginationComponent implements ControlValueAccessor, OnInit {

onChange: any = Function.prototype;
onTouched: any = Function.prototype;
renderer: Renderer2;
elementRef: ElementRef;

classMap: string;
pages: any[];

Expand All @@ -131,9 +131,10 @@ export class PaginationComponent implements ControlValueAccessor, OnInit {
protected _page = 1;

constructor(
renderer: Renderer2,
elementRef: ElementRef,
paginationConfig: PaginationConfig
private renderer: Renderer2,
private elementRef: ElementRef,
paginationConfig: PaginationConfig,
private changeDetection: ChangeDetectorRef
) {
this.renderer = renderer;
this.elementRef = elementRef;
Expand Down

0 comments on commit e225da7

Please sign in to comment.