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

452
Visualizações
Angular, how do you detect when an animation finishes?

I am trying to detect when an animation finishes so that I can execute something afterwards, my research has led me the @animation.done and @animation.start but it seems to fire in the beginning regardless of if my animation is finished.

I consolelog'd a message in my @animation.done function and it fires in the beginning even before the animation happens I believe

https://stackblitz.com/edit/angular-vtuydu?file=src/app/app.component.ts

HTML:

<button
  type="button"
  class="button-viewproject"
  [@fadeInUpViewProject]="viewProjectState ? 'in' : 'out'"
  (@fadeInUpViewProject.done)="animationDone($event)"
>
  View Me
</button>

TS:

  animationDone(event: any) {
    console.log(this.viewProjectState); // alert('hey'); Seems to execute no matter what
    // alert('hey'); Seems to execute no matter what
    setTimeout(() => {}, 1900);
  }
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

If you look at the AnimationEvent object passed into your animationDone() method, you'll see that the method gets called twice: once for going from state 'void' to state 'out', then a second time for going from state 'out' to state 'in':

Call #1 event:

{
  "element": {},
  "triggerName": "fadeInUpViewProject",
  "fromState": "void", <----------------
  "toState": "out", <-------------------
  "phaseName": "done",
  "totalTime": 0,
  "disabled": false,
  "_data": 1
}

Call #2 event:

{
  "element": {},
  "triggerName": "fadeInUpViewProject",
  "fromState": "out", <-----------------
  "toState": "in", <--------------------
  "phaseName": "done",
  "totalTime": 2000,
  "disabled": false,
  "_data": 3
}

The 2nd event is the one that occurs when your fade-in-up animation actually completes (because it's reached your final state of 'in'), so in your animationDone() method, you can just check the passed-in event object's toState property being 'in', then you know your animation is complete.

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