Last active
November 5, 2017 16:26
-
-
Save tomodutch/4b501f7090c4a6c386bc9073af4cbcf5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {Component, OnInit} from '@angular/core'; | |
import {PaymentService} from '../payment.service'; | |
import {Payment} from '../payment'; | |
import 'rxjs/add/operator/debounceTime'; | |
import 'rxjs/add/operator/distinctUntilChanged'; | |
import 'rxjs/add/operator/switchMap'; | |
import {Subject} from 'rxjs/Subject'; | |
@Component({ | |
selector: 'app-dashboard', | |
templateUrl: './dashboard.component.html', | |
styleUrls: ['./dashboard.component.css'] | |
}) | |
export class DashboardComponent implements OnInit { | |
public payments: Payment[] = []; | |
private paginateSubject = new Subject<number>(); | |
public page = 1; | |
constructor(private paymentService: PaymentService) { | |
} | |
ngOnInit() { | |
this.paginateSubject | |
.debounceTime(100) | |
.distinctUntilChanged() | |
.switchMap(page => this.paymentService.getPayments(page)) | |
.subscribe(payments => this.payments = payments); | |
this.switchPage(); | |
} | |
switchPage(): void { | |
this.paginateSubject.next(this.page); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment