Created
February 12, 2021 06:35
-
-
Save charliejlevine/08933191ad4d9bb51511ed72ccde004e to your computer and use it in GitHub Desktop.
This file contains 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 { 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