Skip to content

Instantly share code, notes, and snippets.

@charliejlevine
Created February 12, 2021 06:35
Show Gist options
  • Save charliejlevine/08933191ad4d9bb51511ed72ccde004e to your computer and use it in GitHub Desktop.
Save charliejlevine/08933191ad4d9bb51511ed72ccde004e to your computer and use it in GitHub Desktop.
import { Component, OnInit } from '@angular/core';
import { Brewery } from './brewery.model';
import { BreweryService } from './brewery.service';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss'],
})
export class AppComponent implements OnInit {
throttle = 0;
distance = 2;
page = 1;
breweries: Brewery[] | any[] = [];
constructor(private breweryService: BreweryService) {}
ngOnInit(): void {
this.breweryService
.getBreweries(this.page)
.subscribe((breweries: Brewery[]) => {
this.breweries = breweries;
});
}
onScroll(): void {
this.breweryService
.getBreweries(++this.page)
.subscribe((breweries: Brewery[]) => {
this.breweries.push(...breweries);
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment