按下后退按钮后,保持计时器活动,Ionic 2 Observable.timer

时间:2018-04-02 13:01:21

标签: angular ionic-framework ionic2 ionic3

我的页面Observable.timer上有一个计时器,当它结束时会触发nav.push到另一个页面。但是,当我单击应用程序或硬件后退按钮内的后退按钮时,Observable.timer会触发nav.push。即使返回导航堆栈,如何使计时器倒计时?

  countDown: any;
  counter = 1*10;
  tick = 1000;
  status:any;

  constructor(public modalCtrl: ModalController, public navCtrl: NavController, public navParams: NavParams,  public storage: Storage,  public viewCtrl: ViewController) {
      this.startTimer();
  }
          startTimer() {
            this.countDown = Observable.timer(0, this.tick)
              .take(this.counter)
              .map(() => --this.counter).finally(() => this.endTimer());
              //this.countDown.subscribe(() => { }); 
          }

0 个答案:

没有答案