Created
August 10, 2017 14:56
-
-
Save premsh/41ab4d61e50fa6b9bf82b33fe0866b5d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component } from '@angular/core'; | |
import { Observable } from 'rxjs/Observable'; | |
import { Subject } from 'rxjs/Subject'; | |
import 'rxjs/add/observable/interval'; | |
import 'rxjs/add/operator/map'; | |
import 'rxjs/add/observable/merge'; | |
import 'rxjs/add/operator/startWith'; | |
import 'rxjs/add/operator/scan'; | |
@Component({ | |
selector: 'app-root', | |
templateUrl: './app.component.html', | |
styleUrls: ['./app.component.css'] | |
}) | |
export class AppComponent { | |
clock: Observable<any>; | |
clock$ = new Subject(); | |
constructor() { | |
this.clock = Observable.merge(this.clock$, | |
Observable.interval(3000)) | |
.startWith(new Date()) | |
.scan((accu: Date, current) => { | |
const date = new Date(accu.getTime()); | |
date.setSeconds(date.getSeconds() + 1); | |
return date; | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment