0

How i can update my API (get) with this function setInterval()

I have this this get func.:

getServices(){
    return this._http.get(this._url)
                    .map(res => res.json());
}   

And i would to refresh my data (get json data) every 1 second

I found this example, but this function only show logs every one second, and how update my API with get?

 setInterval(function (getServices) {
             console.log("Test")
         }, 1000)
Eduard Arevshatyan
  • 648
  • 3
  • 18
  • 34

2 Answers2

1

Should probably be something like:

setInterval(() => {
    this. getServices();
    console.log("Test")
}, 1000);

But as your question is not very clear, it's hard to know for sure.

Nitzan Tomer
  • 155,636
  • 47
  • 315
  • 299
0

I guess you mean that you have a function getServices which you want to call every second and do something with the result.

This is how you can do this:

setInterval(() => {
    let result = getServices();
    console.log(result);
}, 1000)

Playground with working example - Run and open console (F12), you will see data is being added to console every second.

Andrey Klochkov
  • 168
  • 1
  • 10