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

171
Views
I created a `const` inside `this.api.getApi().subscribe(({tool,beuty})`, how can I run it inside my `if` statement?

I created a const inside this.api.getApi().subscribe(({tool,beuty}), how can I run it inside my if statement like this:

if (evt.index === 0) {aa}

I will create more lines like this and I want to run them with different if statements:

this.beu=beuty.slice(0,this.i+=15);

Is there a better solution to do that?

Code:

  onScrollDown(evt:any ) {     
    setTimeout(()=>{      
        this.api.getApi().subscribe(({tool,beuty}) => {       
            const aa=this.beu=beuty.slice(0,this.i+=15);
        })
    if (evt.index === 0) {aa}       
    },1000);
  }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can't access a variable declared using const outside its block scope. Try the following and you will get an ReferenceError:

function foo() {
    const bar = "bar";
}
console.log(bar);

So, you can't use aa outside of the callback passed to this.api.getApi().subscribe().

If you want to be able to use aa outside of the callback you can define aa using let. In code:


  onScrollDown(evt:any) {
      
    setTimeout(() => {

        // Add this:
        let aa;
         
        this.api.getApi().subscribe(({tool,beuty}) => {
            // Change this:
            aa=this.beu=beuty.slice(0,this.i+=15);
        })
     
        if (evt.index === 0) {aa}
            
    }, 1000);
   

  }

I hope this helps. I can't really tell if it works because I don't have the whole script.

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!