I am trying to load data in chunks on timely basis. for this I am using thee methods.
This function loads data from a json object that I am using to mimic api data
getScrollingData(startIndex, endIndex){
if(this.items.data.length>endIndex){
return of(this.items.data.slice(startIndex, endIndex));
}else{
return of(null)
}
}
The getData method below is being used to send request every two seconds
getData(){
const secondsCounter = interval(2000);
return secondsCounter
.pipe(
flatMap((res) => {
if(res!=null)
return this.mimicApiService.getScrollingData(res, res+10)
.takeUntil(v => v != null)// this causes error
}),
)
}
In the ngOnInit of component I am subscribing to getData to load that data into array to be displayed on the screen
data = [];
ngOnInit() {
this.dataService.getData().subscribe((res)=>{
this.data = [...this.data, ...res];
});
}
Questions
- I am getting error
Argument of type '(v: any) => boolean' is not assignable to parameter of type 'Observable<any>'from takeUntil. Can you please tell why this happens?