我有这样的服务
channelList = [];
getChannels(): Observable<any> {
if (this.channelList.length) {
return this.channelList;
} else {
return this.http.get(
environment.apiUrl + '/channels'
).pipe(map((res) => {
this.channelList = res.json().results.items;
return this.channelList;
}));
}
}
我正在做什么,我正在检查是否存储了数据,然后将其返回,否则按api
但是TS给我一个类似Type 'any[]' is not assignable to type 'Observable<any>'.
Property '_isScalar' is missing in type 'any[]'.
我该如何解决?
我正在像这样的组件中使用它
this.myService.getChannels()
.subscribe(result => {
this.channelsData = result;
});