Issue
i have tried this
Time Left={{counter}}
but it show me just in second format.
i want in hh:mm:ss format.
i want to implement his functionality in quiz timer where timer is decreased.
in my .ts file i take var counter and decrement using .map method using angular OBSERVABLE method.
i want to decrement the timer to end up the quiz. For example:1:20:60 to 0:0:0. When the timer is over i want to submit the quiz.
starttimer(){
this.countDown = Observable.timer(0,1000)
.take(this.counter)
.map( x=> --this.counter)
.subscribe(x=>this.timer(x))
}
Solution
I implemented this code by my own
var callDuration = this.elementRef.nativeElement.querySelector('#time');
this.startTimer(callDuration);
startTimer(display){
var timer = 3600;
var minutes;
var seconds;
var hours;
this.display1=display;
this.sub = Observable.interval(1000).subscribe(x => {
hours = Math.floor(timer / 3600)
minutes = Math.floor((timer % 3600)/60);
seconds = Math.floor(timer % 60);
hours = minutes < 10 ? "0" + hours : hours;
minutes = minutes < 10 ? "0" + minutes : minutes;
seconds = seconds < 10 ? "0" + seconds : seconds;
display.textContent = hours + ":" + minutes + ":" + seconds;
--timer;
if (timer < -1) {
this.sub.unsubscribe();
display.textContent ="00:00:00";
window.alert("Times Up, Quiz Submitted");
Answered By - Sid Kasundra
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.