Oi gente, seguindo os passos do professor, cheguei ao ponto em que o botão Load More não consegue aparecer mesmo havendo duas páginas de dados na API. O erro que aparece chega a ser até estranho.
ERROR TypeError: _this.photos.concat is not a function
at SafeSubscriber._next (photo-list.component.ts:43)
at SafeSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.SafeSubscriber.__tryOrUnsub (Subscriber.js:253)
at SafeSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.SafeSubscriber.next (Subscriber.js:191)
at Subscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber._next (Subscriber.js:129)
at Subscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.next (Subscriber.js:93)
at MapSubscriber.push../node_modules/rxjs/_esm5/internal/operators/map.js.MapSubscriber._next (map.js:81)
at MapSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.next (Subscriber.js:93)
at FilterSubscriber.push../node_modules/rxjs/_esm5/internal/operators/filter.js.FilterSubscriber._next (filter.js:85)
at FilterSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.next (Subscriber.js:93)
at MergeMapSubscriber.push../node_modules/rxjs/_esm5/internal/operators/mergeMap.js.MergeMapSubscriber.notifyNext (mergeMap.js:136)
photo-list.component.ts
import { Component, OnInit, OnDestroy } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { Photo } from '../photo/photo';
import { Subject } from 'rxjs';
import { debounceTime } from 'rxjs/operators';
import { PhotoService } from '../photo/photo.service';
@Component({
selector: 'ap-photo-list',
templateUrl: './photo-list.component.html',
styleUrls: ['./photo-list.component.css']
})
export class PhotoListComponent implements OnInit, OnDestroy {
photos: Photo[] = [];
filter: string = '';
debounce: Subject<string> = new Subject<string>();
hasMore: boolean = false;
currentPage: number = 0;
userId: number = 0;
constructor(
private actvatedRoute: ActivatedRoute,
private photoService: PhotoService
) { }
ngOnInit(): void {
this.userId = this.actvatedRoute.snapshot.params.userId;
this.photos = this.actvatedRoute.snapshot.data['photos'];
this.debounce
.pipe(debounceTime(300))
.subscribe(filter => this.filter = filter);
}
ngOnDestroy(): void {
this.debounce.unsubscribe();
}
load() {
this.photoService
.listFromUserPaginated(this.userId, ++this.currentPage)
.subscribe(photos => {
this.photos = this.photos.concat(photos);
if(!photos.length) this.hasMore = false;
});
}
}