我正在尝试使用+----+-----+------+------+-------+------+
| | Grp | Org1 | Org2 | Value | FLAG |
+----+-----+------+------+-------+------+
| 0 | 1 | x | a | 0 | 0 |
| 1 | 1 | x | a | 0 | 0 |
| 2 | 1 | y | b | 3 | 1 |
| 3 | 1 | y | b | 1 | 0 |
| 4 | 2 | z | c | 0 | 0 |
| 5 | 2 | y | b | 1 | 1 |
| 6 | 2 | z | c | 0 | 0 |
| 7 | 2 | z | c | 5 | 1 |
| 8 | 3 | x | a | 0 | 0 |
| 9 | 3 | y | b | 0 | 0 |
| 10 | 3 | y | b | 0 | 0 |
| 11 | 4 | z | c | 1 | 1 |
| 12 | 4 | x | a | 1 | 1 |
| 13 | 4 | x | a | 1 | 0 |
+----+-----+------+------+-------+------+
和interval
使用RxJS从服务器轮询实时数据。当用户导航到组件时,它将触发轮询。我通过使用以下服务代码直接请求HTTP端点(而不是扩展基类)来使其工作。
myService.ts:
switchMap
但是,我无法理解为什么扩展基本服务类并在基类中执行相同的操作会导致错误
myService.ts:
public getRealTimeData() {
return interval(5000).pipe(
switchMap(() => {
return this.httpClient.get('http://myendpoint:3000/endpoint');
}),
catchError((err) => {
console.log('Handling error locally and rethrowing it...', err);
return throwError(err);
})
);
}
baseService.ts:
...
constructor(){
super(httpClient, 'my_custom_route')
}
public getRealTimeDataExtendingBaseClass() {
return interval(5000).pipe(
switchMap(() => {
this.requestURLBase();
}),
catchError((err) => {
console.log('Handling error locally and rethrowing it...', err);
return throwError(err);
})
);
}
这是错误堆栈:
protected baseUrlPrefix = 'api/v1/';
constructor(protected httpClient: HttpClient, route: string) {
this.route = route;
}
...
public requestURLBase() {
return this.httpClient.get(this.baseUrlPrefix + this.url);
}
答案 0 :(得分:1)
您忘记了返回请求流。
switchMap(() => {
return this.requestURLBase(); // <- return!!!
}),