Javascript 角度反转定时器和md选择
我想创建一个循环反向定时器,用户应该能够选择原点号。在my md select中,应选择等于10的值。我试图通过使用变量count解决此问题,但它与选择的第一个值time=10关联。。。我认为需要使用计数器,但不知道如何正确操作。或者我需要添加设置为md select或与以下值相关联的selectedTime。怎么做Javascript 角度反转定时器和md选择,javascript,angular,typescript,timer,md-select,Javascript,Angular,Typescript,Timer,Md Select,我想创建一个循环反向定时器,用户应该能够选择原点号。在my md select中,应选择等于10的值。我试图通过使用变量count解决此问题,但它与选择的第一个值time=10关联。。。我认为需要使用计数器,但不知道如何正确操作。或者我需要添加设置为md select或与以下值相关联的selectedTime。怎么做 import { Component, OnInit } from '@angular/core'; import { SimpleTimer } from 'ng
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>-->
{{up_time.viewValue}}
{{selectedTime}}