我想创建循环反向计时器,用户应该可以选择原始编号。在我的 md-select 中应该选择等于 10 的值。我试图通过使用变量 count 来解决这个问题,但它与第一个值 selectedTime = 10 相关联...我认为需要使用计数器但不知道怎么做对。或者我需要添加设置 md-select 或以其他方式与以下值相关联 selectedTime。怎么做??
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;
// }
// }
我的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>-->