Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

172
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda