Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

228
Views
Condición de temporizador observable de Angular2

tengo un temporizador:

 initiateTimer() { if (this.timerSub) this.destroyTimer(); let timer = TimerObservable.create(0, 1000); this.timerSub = timer.subscribe(t => { this.secondTicks = t }); }

¿Cómo agregaría la condición después de 60 minutos para presentar una ventana emergente al usuario? Intenté ver un par de preguntas ( this y this ) pero no me funciona. Todavía nuevo en los patrones RxJS...

about 4 years ago · Santiago Trujillo
3 answers
Answer question

0

No necesitas RxJS para eso. Puedes usar el viejo setTimeout :

 initiateTimer() { if (this.timer) { clearTimeout(this.timer); } this.timer = setTimeout(this.showPopup.bind(this), 60 * 60 * 1000); }

Si realmente debe usar RxJS, podría:

 initiateTimer() { if (this.timerSub) { this.timerSub.unsubscribe(); } this.timerSub = Rx.Observable.timer(60 * 60 * 1000) .take(1) .subscribe(this.showPopup.bind(this)); }
about 4 years ago · Santiago Trujillo Report

0

Simplemente use observable.timer y suscríbase.

 import { Component } from '@angular/core'; import { Observable } from 'rxjs/Rx'; @Component({ selector: 'app-root', templateUrl: './app.component.html', }) export class AppComponent { title = 'app works!'; constructor(){ var numbers = Observable.timer(10000); // Call after 10 second.. Please set your time numbers.subscribe(x =>{ alert("10 second"); }); } }

Por favor vea más detalles

about 4 years ago · Santiago Trujillo Report

0

Terminé haciendo esto a partir de lo que tenía inicialmente, lo que me da lo que necesito:

 initiateTimer() { if (this.timerSub) this.destroyTimer(); let timer = TimerObservable.create(0, 1000); let hour = 3600; this.timerSub = timer.subscribe(t => { this.secondTicks = t; if (this.secondTicks > hour) { alert("Save your work!"); hour = hour * 2; } }); }

Implementé esto antes de probar lo que marqué como respuesta, así que lo dejaré aquí.

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!