Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save automactic/7c57aff8ff8ad7778a58df106c175152 to your computer and use it in GitHub Desktop.
Save automactic/7c57aff8ff8ad7778a58df106c175152 to your computer and use it in GitHub Desktop.
angular2 timer
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