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

138
Vistas
How to call a method of a class from an rxjs observable subscription

Could I please ask:

This code works fine:

class MyClass
{
  constructor()
  {
    this.m_observable = Rx.Observable.of(1, 2);
    
      this.m_observable.subscribe(
                                 function (x) {alert(x);}
                                 );
  }
  
  DoIt(x)
  {
    alert(5 * x);
  }
}

When I create a new instance of the class I see "1" then "2".

I would like to call the DoIt method of the class when the subscription fires, this code does not work, I see no alerts:

class rxjsShapeShifter
{
  constructor()
  {
    this.m_observable = Rx.Observable.of(1, 2);
    
      this.m_observable.subscribe(
                                 this.DoIt;
                                 );
  }
  
  DoIt(x)
  {
    alert(5 * x);
  }
}

How can I call that method from the observable subscription?

Thanks for any help.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I think you have typo in your subscribe. The second code of your should be:

    constructor() {
      this.m_observable = Rx.Observable.of(1, 2);
      this.m_observable.subscribe(this.DoIt);
    }
    
    DoIt(x) {
      alert(5 * x);
    }
about 4 years ago · Juan Pablo Isaza 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