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

185
Visualizações
idangero.us Swiper with Angular - How to keep scope in config callback

I've been trying to understand working with callbacks to be able to keep the scope on a callback that I am trying to run but am still missing something.

Swiper (for Angular at least) uses "config" to set pagination, slidesPerView, etc. including what to do when the user reaches the last slide (onReachEnd) but I can't maintain my scope inside of that callback which looks like this:

config: any = {
      pagination: '.swiper-pagination',
      ...
      ...
      onReachEnd: function(swiper){
        console.log(this.userName);
      }
  };

and returns "undefined" for this.userName.

I've tried to use bind inside the onReachEnd callback but "this" is already undefined which makes me think I have to plug it in at a higher level but am not sure how that works or if that is either the correct way to go about this.

Thanks for any input or advice!

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

So I found another problem on a forum that happened to list an example of that I needed so in case anyone has a similar problem here is the answer, it is a lot simpler than I imagined. If this is not a solid way to do this please let me know.

onReachEnd: () => {
          this.yourFunctionHere();
        }
over 4 years ago · Santiago Trujillo 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