Angular 5+ Create a timer that informs, seconds, minutes, hours, etc.

0

Well, I need to start a timer in the application, when it enters the device page, and when I click on stop, I'll save that time information and perform specific calculations.

This is the part of my functional code, here I can count the seconds normally, I want to know if you have an idea or a better alternative for me to adopt.

import { Subscription } from "rxjs";
import { TimerObservable } from "rxjs/observable/TimerObservable";

export class DevicesComponent implements OnInit, OnDestroy {

ngOnInit() {
    let timer = TimerObservable.create(2000,1000);
    this.subscription = timer.subscribe(t => {
      this.tick = t;
      console.log(this.tick);
    })
  }

  ngOnDestroy() {
    this.subscription.unsubscribe();
  }

}
    
asked by anonymous 01.07.2018 / 23:39

0 answers