【发布时间】:2021-03-09 22:37:34
【问题描述】:
我正在尝试按时分块加载数据。为此,我正在使用你的方法。
此函数从我用来模拟 api 数据的 json 对象加载数据
getScrollingData(startIndex, endIndex){
if(this.items.data.length>endIndex){
return of(this.items.data.slice(startIndex, endIndex));
}else{
return of(null)
}
}
下面的 getData 方法用于每两秒发送一次请求
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
}),
)
}
在组件的 ngOnInit 中,我订阅了 getData 以将该数据加载到要在屏幕上显示的数组中
data = [];
ngOnInit() {
this.dataService.getData().subscribe((res)=>{
this.data = [...this.data, ...res];
});
}
问题
- 我从 takeUntil 收到错误
Argument of type '(v: any) => boolean' is not assignable to parameter of type 'Observable<any>'。你能说出为什么会这样吗?
【问题讨论】: