Trying to retrieve data from a service using setInterval has posed an issue for me. When I call the service from ngOnInit, everything functions as expected. However, when attempting to call it from any other function, an error occurs:
"ERROR TypeError: Cannot read property 'get' of undefined"
public apiCall(mints:number){
console.log("from setInterval");
// console.log("api called");
// this.refInrvl=setInterval(()=>{
this.http.get('https://jsonplaceholder.typicode.com/posts').subscribe(resp=>{
this.storeD=resp;
});
// },3000)
}
public refreshSearch(){
console.log(this.refMints);
this.setIntvl();
}
public refreshList(refMints:number){
//this.refMints=refMints;
console.log("Sel Number",this.refMints);
this.setIntvl();
}
public setIntvl(){
this.refInrvl=setInterval(this.apiCall,(this.refMints*300*60),this.refMints);
}