0
点赞
收藏
分享

微信扫一扫

Angular定时器

夏沐沐 2022-03-30 阅读 50
import { Component } from '@angular/core';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  title = 'untitled2906';
  select= 0;//页面对应抽奖下标
  timer:any;

  ngOnInit() {
    this.timer = setInterval(() => {
      this.spinPrize()
    }, 500)
  }

  spinPrize() {
    this.select += 1
    console.log("定时器为:" + this.select )

    if (this.select == 5 ) {
      clearInterval(this.timer)
      console.log("中奖产品为:" + this.select )
    }
  }
}
举报

相关推荐

0 条评论