Reputation: 1079
I have a Behaviour Subject in my application. and i subscribed that Behaviour Subject as below.
tableData: BehaviorSubject<any> = new BehaviorSubject([]);
i am using next() method to set data from some other function as below
for (let item of data) {
let objArr = [];
// some code here like for loop (i am processing 100k records)
objArr.push(object);
if (objArr.length == 20) {
this.tableData.next(objArr);
objArr = [];
}
}
I have subscribed this BehaviourSubject as below. but i am unable to show all records from DB.
this.data = [];
this.utilServ.tableData.subscribe((data) => {
if (data.length !== 0) {
for (let item of data) {
this.data.push(item);
}
}
});
this.utilServ.tableData.next([]);
It is only showing last records.
How to combine/merge/concat the data from Behaviour Subject?
Upvotes: 1
Views: 71
Reputation: 2947
When you use next of behaviorSubject
you can use next on accumulated array.
One way is to write like this
const newValue = this.tableData.value.concat(objArr);
this.tableData.next(newValue);
Upvotes: 2