export class AppComponent implements OnInit { throttle = 0; distance = 2; page = 1; li: any; lis: any = []; constructor(private characterService: CharacterService) {} ngOnInit(): void { this.characterService.getCharacters(this.page).subscribe((Response) => { console.log(Response); this.li = Response; this.lis = this.li.results; }); } onScroll(): void { this.characterService.getCharacters(++this.page).subscribe((Response) => { console.log("New fetch"); this.li = Response; this.lis = this.li.results; }); }
export class CharacterService { constructor(private http: HttpClient) {} getCharacters(page: number) { return this.http.get( `https://rickandmortyapi.com/api/character?page=${page}&per_page=20` ); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)