Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

177
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda