Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 离子2可观察到。计时器在后退按钮上被破坏_Angular_Ionic Framework_Ionic2 - Fatal编程技术网

Angular 离子2可观察到。计时器在后退按钮上被破坏

Angular 离子2可观察到。计时器在后退按钮上被破坏,angular,ionic-framework,ionic2,Angular,Ionic Framework,Ionic2,我有一个Observable.timer倒计时,当用户离开页面时,如果他们决定稍后回来,我希望该计时器仍然处于活动状态。例如,我只希望在到达特定日期和时间时删除计时器 我曾尝试实现此功能,但当我单击“上一步”按钮时,计时器将被销毁,并调用endTimer()回调函数 定时器功能 countDown: any; counter = 1*900; tick = 1000; newtimer() { // create session this.storage.se

我有一个
Observable.timer
倒计时,当用户离开页面时,如果他们决定稍后回来,我希望该计时器仍然处于活动状态。例如,我只希望在到达特定日期和时间时删除计时器

我曾尝试实现此功能,但当我单击“上一步”按钮时,计时器将被销毁,并调用endTimer()回调函数

定时器功能

   countDown: any;
   counter = 1*900;
   tick = 1000;

 newtimer() {
   // create session 
   this.storage.set('dateCreated', 'timer_started');
   // create timer
   this.countDown = Observable.timer(0, this.tick)
      .take(this.counter)
      .map(() => --this.counter).finally(() => this.endTimer()); 
 }

当你在爱奥尼亚留下一页时,它将被销毁。因此,作为该页的成员变量的计时器被销毁


如果你想让计时器继续运行,你应该把它投入一些服务中。因为服务是单例的,所以在删除页面时不会销毁该服务。

这是针对特定页面的吗?还是更像是整个应用程序的会话?你在哪里调用你的函数
newtimer()
?听起来你在组件/页面中有这个函数,而它在服务中更好地为你服务。它是针对特定页面的。它是在页面的构造函数中使用计时器函数调用的。我已将其添加到服务中,但当我退出页面时计时器仍然会结束,如果我尝试重新进入页面,它将从Scratch重新开始。如何导入和注入服务?