我正在使用以下代码来订阅我的连接API,但是我收到以下错误。 每5秒调用一次使用的getconnection()函数。
getConnections() {
this.httpClient.get('/api/api_server.json').subscribe(
(apipath: any) => {
this.apiDataService.connectionStatusService = setInterval(() => {
this.httpClient.get(apipath['server']+'/api/connection').subscribe((res: any[]) => {
console.log(res);
var data: any = res;
this.observers.connectionAsObserver.next(data[0]);
});
}, 5000);
});
}
数据包含
[{ “ current_timestamp”:“ 2020-09-13T23:07:28”, “ machine_name”:“ raiod”, “状态”:“确定” }]
ERROR TypeError: Cannot read property 'next' of undefined
at SafeSubscriber._next (app-data.service.ts:849)
at SafeSubscriber.__tryOrUnsub (Subscriber.js:185)
at SafeSubscriber.next (Subscriber.js:124)
at Subscriber._next (Subscriber.js:72)
at Subscriber.next (Subscriber.js:49)