¿Podría por favor preguntar:
Este código funciona bien:
class MyClass { constructor() { this.m_observable = Rx.Observable.of(1, 2); this.m_observable.subscribe( function (x) {alert(x);} ); } DoIt(x) { alert(5 * x); } }Cuando creo una nueva instancia de la clase, veo "1" y luego "2".
Me gustaría llamar al método DoIt de la clase cuando se activa la suscripción, este código no funciona, no veo alertas:
class rxjsShapeShifter { constructor() { this.m_observable = Rx.Observable.of(1, 2); this.m_observable.subscribe( this.DoIt; ); } DoIt(x) { alert(5 * x); } }¿Cómo puedo llamar a ese método desde la suscripción observable?
Gracias por cualquier ayuda.
Creo que tienes un error tipográfico en tu subscribe . El segundo código de su debe ser:
constructor() { this.m_observable = Rx.Observable.of(1, 2); this.m_observable.subscribe(this.DoIt); } DoIt(x) { alert(5 * x); }