I am willing to do a countdown timer in Angular 2 that start from 60 (i.e 59, 58,57, etc...)
For that I have the following:
constructor(){
Observable.timer(0,1000).subscribe(timer=>{
this.counter = timer;
});
}
The above, ticks every second, which is fine; however, it goes in an ascending order to an unlimited number. I am not sure if there is a way to tweak it so I can have a countdown timer.
Import into Component:
Function CountDown:
Html :
There are many way to achieve this, a basic example is to use the
take
operatorHere is a live plnkr
Update
A better way! create a counter directive
Usage:
Here is a live stackblitz