Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

238
Vistas
Unsubscribe from a observable when condition is true in angular

I'm trying close a popup after 5 seconds when it is loaded but the subscription finish before so i want to unsubscribe when the variable loaded is true

    this.closed = false;
    this.loaded$.subscribe(loaded => {
      if (loaded) {
        setTimeout(() => {
          this.modalService.dismissActiveModal();
        }, 5000);
      }
    }).unsubscribe();
  } 
about 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

this.closed = false;
// define the subscription
const subscription: Subscription = this.loaded$.subscribe(loaded => {
  if (loaded) {
    setTimeout(() => {
      this.modalService.dismissActiveModal();
      subscription.unsubscribe(); // unsubscribe here
    }, 5000);
  }
});

How about this?

about 4 years ago · Santiago Trujillo Denunciar

0

this.closed = false;
this.loaded$
.pipe(
  filter(loaded => loaded),
  switchMap(_ => interval(5000)),
  take(1),
  tap(_ => this.modalService.dismissActiveModal())
)
.subscribe();
about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda