ionic3、Angular4 定时器的使用
// 声明变量
applicationInterval:any; // 定时器
// 使用定时器,每秒执行一次
ionViewDidEnter(){
let that = this;
let applicationPageOpenData:number = parseInt(((new Date().getTime()/1000)+30).toString());
let nowDte:number;
this.nextBtnText = "30秒后方可点击"; // 按钮文本
this.nextBtnBool = false; // 按钮是否可点击标识
this.applicationInterval = setInterval(() => {
nowDte = parseInt((new Date().getTime()/1000).toString());
let receiveDate = applicationPageOpenData - nowDte;
if(receiveDate>0){
that.nextBtnText = receiveDate +"秒后方可点击";
}else{
that.nextBtnText = "下一步";
that.nextBtnBool = true;
// 停止定时器
clearInterval(that.applicationInterval);
}
}, 1000);
}
// 本例,30秒后按钮方可点击