In my template I subscribe to an observable array like so:
<div *ngFor="let item of activities | async">...</div>
I changed my activities array to an observable array because I like the idea of the view subscribing and unsubscribing from my observables.
My question is, after initially retrieving the observables and mapping them into an activities object array, how do I append or prepend activities to that array without overwriting the entire observable array?
To be specific, I am creating an infinite scroll and upon the new http request completing, I have 12 new activity objects that I need to append to the activities observable array.
Activities definition:
public activities: Observable<Array<ActivitiesItemModel>>;
My initial request:
this.activities = this._transactionService.Get(url)
.map(activities => {
// Creates an activities model which contains items<ActivitiesItemModel>
return new activitiesModel(activities).items;
})
My infinite scroll request:
// This is where I am stuck..
// I assumed I could just map the values retrieved from the request
this.activities
.map(a => {
return this._transactionService.Get(queryUrl)
.map(activities => {
infiniteScroll.complete();
return activities;
})
})
Any ideas?
ChangeDetectionStrategy.OnPush, which doesn't work if you mutate array, that's why it's better to overwrite it. Keep your downloaded data in one place and use filtered copy of this data for display...