Animation inside of MatDialog is not working

﹥>﹥吖頭↗ 提交于 2019-12-11 04:46:15

问题


I have component/dialog where I am going dynamically add/remove components. Also I do have animation on enter/leave so when component is removed and new component added I want to animate slide in slide out. But inside of MatDialog is not working.

I thought issue is with animation but when I am inserting my component, which I am showing in dialog, to any other place which is rendered with Mat Dialog it works.

  <mat-dialog-content>
      <div  [@swapComponent]="getStatus()"
      (@swapComponent.start)="animationStart($event)"  (@swapComponent.done)="animationDone($event)"
      style="display:block">
        <ng-template #container>
        </ng-template>
        </div>
    </mat-dialog-content>

on start and done i am printing to console, and those events are called even animation is not working.

I am using @angular/material 6.3.0


回答1:


I solved my issue using Animation Builder.

constructor(private animationBuilder: AnimationBuilder){
    this.openAnimation = this.animationBuilder.build([
      style({
        opacity: 0,
        transform: 'translate3d({{offsetEnterX}}%,{{offsetEnterY}}%,0)'
      }),
      group([
        animate('0.8s cubic-bezier(0,0,.2,1)', style({ opacity: 1 })),
        animate(
          '0.5s cubic-bezier(0,0,.2,1)',
          style({ transform: 'translate3d(0,0,0)' })
        )
      ])
    ]);
}

Then i can play animation

 const player = this.openAnimation.create(
      component.location.nativeElement,
      this.getStatus()
    );
    player.onDone(() => {
      player.destroy();
    });
    player.play();

Problem is that angular animation is not playing sub animation and since angular material has animation to fadein/out modal my animation triggers inside of modal are not working.



来源:https://stackoverflow.com/questions/52656510/animation-inside-of-matdialog-is-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!