I want to create cyclic reverse timer and user should be able choose the origin number. In my md-select should be selected value which equal 10. I tried to resolve this issue by using variable countbut it is associated with the first value selectedTime = 10... I think that need to use counter but do not know how do it right.Or i need to add is set md-select or otherwise associate with the following values selectedTime. How do it??
import { Component, OnInit } from '@angular/core';
import { SimpleTimer } from 'ng2-simple-timer';
@Component({
selector: 'app-main-map',
templateUrl: './main-map.component.html',
styleUrls: ['./main-map.component.css'],
})
export class MainMapComponent implements OnInit {
selectedTime: number = 10;
// counter: number = this.selectedTime;
up_times = [
{value: '999', viewValue: 'Не оновлювати'},
{value: '5', viewValue: '5 sec'},
{value: '10', viewValue: '10 sec'},
{value: '15', viewValue: '15 sec'},
{value: '30', viewValue: '30 sec'},
{value: '60', viewValue: '1 min'},
{value: '300', viewValue: '5 min'},
{value: '600', viewValue: '10 min'},
];
constructor(private st: SimpleTimer) { }
ngOnInit() {
this.st.newTimer('1sec',1);
this.subscribeTimer0();
}
subscribeTimer0() {
if (this.selectedTime == 999) {
this.st.unsubscribe(this.timer0Id);
this.timer0Id = undefined;
} else {
this.timer0Id = this.st.subscribe('1sec', e => this.timer0callback());
}
console.log(this.st.getSubscription());
}
timer0callback() {
this.selectedTime--;
if(this.selectedTime == 0){
this.selectedTime = selectedTime;
}
}
// timer0callback() {
// this.count--;
// if(this.count == 0){
// this.count = selectedTime;
// }
// }
My html:
<md-select [(ngModel)]="selectedTime" >
<md-option *ngFor="let up_time of up_times" [value]="up_time.value">
{{ up_time.viewValue }}
</md-option>
</md-select>
<div style="top: 13px;position: absolute;left: 127px;">{{selectedTime}}</div>
<!--<div style="top: 13px;position: absolute;left: 127px;">{{count}}</div>-->