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

139
Views
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 answers
Answer question

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 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!