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

108
Views
How to make sure this matches my component instead of the window in a callback function of setInterval

This is my class :

export class GameControlComponent implements OnInit {

  count = 0;
  @Output() num = new EventEmitter<number>();

  private intervalCall;


  ngOnInit(): void {
  }
  
  start(): void {
    this.intervalCall=setInterval(this.sendNumber, 1000); //works
  }
  stop(): void {
    clearInterval(this.intervalCall); //works
  }
  
  sendNumber(this:GameControlComponent){
    console.log(this)//windows
    this.num.emit(this.count); //this.num undefined
    this.count++; // this.count undefined
  }

}

Inside of my function sendNumber call by the setInterval function this corresponds to the windows instead of my component so I can't access my properties.

How to get this be equal to my component ?

Thanks guys !

about 4 years ago · Juan Pablo Isaza
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!