11

I created an element (div.parent) with an Angular animation that worked great. When I add a child element to it and try to animate the child at the same time, one of the animations doesn't end up running (it just snaps to the new state).

Stackblitz: https://stackblitz.com/edit/angular-2tbwu8

Markup:

<div [@theParentAnimation]="state" class="parent">
  <div [@theChildAnimation]="state" class="child">
  </div>
</div>

Animations:

trigger( 'theParentAnimation', [
  state( 'down', style( {
    transform: 'translateY( 100% ) translateZ( 0 )',
  } ) ),
  transition( '* <=> *', [
    group( [
      query( ':self', [
        animate( '0.9s cubic-bezier(0.55, 0.31, 0.15, 0.93)' ),
      ] ),
      query( '@theChildAnimation', animateChild() ),
    ] ),
  ] ),
] ),
trigger( 'theChildAnimation', [
  state( 'down', style( {
    transform: 'translateY( 100% ) translateZ( 0 )',
  } ) ),
  transition( '* <=> *', [
    animate( '0.9s cubic-bezier(0.55, 0.31, 0.15, 0.93)' ),
  ] ),
] ),
Chris Voth
  • 853
  • 5
  • 13
  • 22

1 Answers1

15

It looks like you don't need to use query( ':self', ... since you are using group() animations will run in parallel. You can change the transition in your parent animation:

transition('* <=> *', [
  group([
    query('@theChildAnimation', animateChild()),
    animate('0.9s cubic-bezier(0.55, 0.31, 0.15, 0.93)'),
  ]),
]),

Updated StackBlitz

Michael Doye
  • 8,063
  • 5
  • 40
  • 56
  • I have similar problem I tired using child animation as well but it didn't work. https://stackoverflow.com/questions/63497254/when-i-use-same-angular-animation-on-child-element-it-doesnt-work – indrajeet Sep 03 '20 at 01:58
  • 2
    Thank you! This answer helped me learn how to use animateChild(). To say that the docs lack sufficient explanation would be an understatement. – ModusPwnens Jul 18 '22 at 16:19