Skip to content

Instantly share code, notes, and snippets.

@tomodutch
Last active November 5, 2017 16:26
Show Gist options
  • Save tomodutch/4b501f7090c4a6c386bc9073af4cbcf5 to your computer and use it in GitHub Desktop.
Save tomodutch/4b501f7090c4a6c386bc9073af4cbcf5 to your computer and use it in GitHub Desktop.
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