I am rephrasing my query as I realized it was unclear earlier.
I have an API that is sending me data in the following format:
{"photos":[{"id":1,"title":"photo_1_title"}]}
In my code, I have a variable called photos
and a function named getPhotos()
For implementing infinite scroll, I call getPhotos()
once I reach the bottom of the page.
photos: any;
getPhotos() {
this.photoService.getPhotos()
.subscribe(
photos => this.photos = photos
// However, instead of replacing this.photos with new data, I want to merge the new array of photos using Object.assign, but I'm facing an error.
)
}
When I make another call to get data and receive
{"photos":[{"id":2,"title":"photo_2_title"}]}
, I aim to update this.photos
to look like:
{"photos":[{"id":1,"title":"photo_1_title"}, {"id":2,"title":"photo_2_title"}]}
Could someone assist me in understanding why
jsfiddle.net/ca46hLw9 isn't functioning properly? Isn't the assign method supposed to merge object contents together?