Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //get the server date
- this.service.getServerTime().subscribe(serverDate => {
- this.serverDate = serverDate;
- }, error => { });
- //start the timer using observable
- let timer = Observable.timer(1000, 1000);
- this.timerSubscription = timer.subscribe((t: any) => {
- this.timerExecuted();
- });
- private timerExecuted(): void {
- if (!this.serverDate) {
- return;
- }
- //add 1 second to the server date
- this.serverDate.setSeconds(this.serverDate.getSeconds() + 1);
- //console log the server date after adding 1 second
- console.log(this.serverDate);
- }
Add Comment
Please, Sign In to add comment