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

169
Views
Angular arrow function, "this" is undefined

I am using Angular and call another function that makes an api call to check something. When I call the function, the this inside it is undefined!? why would this be? and how do I fix it? is my arrow function call incorrect?

This is the function that is calling the arrowFunc

onProductChanged(event) {
  this.arrowFunc(hasRangeConfigurations => {
    console.log("do something");
  })
}

This the the function that the above calls, the "this" is undefined in the const declaration at this point, but in the above it is a reference to my angular component.

arrowFunc(action: (hasRangeConfigurations: boolean) => void) {
    const criteria = {
        brandId: this.marketingRange?.brand?.id,
        pageNumber: 1,
        pageSize: 1,
    } as Myresults
    
    // extra code here
});

Interestingly this does exist outside the const but inside the const it is undefined!?

-- UPDATE My Solution--

Well before you know it someone deletes your question and forwards you to something else that is confusing.

As I cant ask a legitimate question as it gets deleted, I solved it this way, just assigning this to self (like I had done back in the jquery/javascript days) I dont know if this is the best solution, but hey hoo!

arrowFunc(action: (hasRangeConfigurations: boolean) => void) {
        const self = this;
        const criteria = {
            brandId: self.marketingRange?.brand?.id,
            pageNumber: 1,
            pageSize: 1,
        } as Myresults
        
        // extra code here
    });
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!