Created
July 11, 2017 15:38
-
-
Save automactic/7c57aff8ff8ad7778a58df106c175152 to your computer and use it in GitHub Desktop.
angular2 timer
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, OnInit, OnDestroy } from '@angular/core'; | |
import { Observable, Subscription } from 'rxjs/Rx'; | |
import { Task } from '../../model/task'; | |
@Component({ | |
selector: 'tasks', | |
templateUrl: './list-tasks.component.html', | |
styleUrls: ['./list-tasks.component.css'] | |
}) | |
export class ListTasksComponent implements OnInit, OnDestroy { | |
tasks: Task[] = [] | |
private ticks = 0; | |
private timer: Observable<number>; | |
private sub: Subscription; | |
ngOnInit(): void { | |
this.timer = Observable.timer(2000,5000); | |
this.sub = this.timer.subscribe(t => this.tickerFunc(t)); | |
} | |
tickerFunc(tick: number){ | |
console.log(this); | |
this.ticks = tick | |
} | |
ngOnDestroy(){ | |
console.log("Destroy timer"); | |
this.sub.unsubscribe(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment