0

I am new to Angular 2. Is there any start timer and stop timer and reset in Angular 2.

For example I want to start a timer before sending a post request and stop the timer after getting response back from the server. Help is appreciated.

executeUserAddressFlow(request: any): any {           
       Start timer here ---->
        return this.http.post(this.Url, req, { headers: sampleHeader })
            .map(
            res => res.json(),
    stop somewhere here ----->
            error => error
            );
    }

i just need to log response time frame.

Thanks

McVenco
  • 1,011
  • 1
  • 17
  • 30
kiranlama
  • 11
  • 1
  • 4
  • For what it's worth, keep in mind that zone.js hijacks timers (and angular 2 uses zone.js). I've seen some people try to do things they think happens "outside" of change detection etc (zones) by using timers, but that doesn't work they way you'd expect unless you deliberately avoid it. – Tim Consolazio May 30 '17 at 19:37

1 Answers1

0

Check out this stackoverflow post How to create Timer in angular2, you can also do it with plain old JavaScript and the setInterval() method along with a for loop and counter.

Vinorth
  • 968
  • 8
  • 13