This project I've been working on involves receiving real-time data from an API. The data is sourced from the API and I collect variables by utilizing a .CSV file stored on the web server of a S7-1500 Siemens.
In order to continuously receive real-time data, I aim to set up a setInterval in my service to execute this function multiple times.
Initially, during the first loop, the API call functions as expected. However, upon subsequent loops, an error arises:
Type Error: Cannot read 'get' of undefined
at line.service.ts
at Array.map(<anonymous>)
at getData(line.service.ts:25).
The issue seems to revolve around http.get during the second iteration, but I've struggled to find a resolution after extensive searches.
Below is the code:
import {BehaviorSubject, combineLatest, Subject, Subscription} from 'rxjs';
import {HttpClient, HttpHeaders} from '@angular/common/http';
import {Injectable, OnDestroy} from '@angular/core';
@Injectable()
export class LineService{
constructor(private http: HttpClient) {
this.getData();
setInterval(this.getData, 5000);
}
lineSubject = new BehaviorSubject<RcvData[]>([]);
getData(): void {
// Function content goes here...
}
}
class RcvData{
// Class definition goes here...
}
I would greatly appreciate any insights or solutions to this problem. Thank you!