angularangular6angular-animationsangular-transitions

Animation transition not working - angular 6


I need to animate when opening and closing a Sidenav

    animations: [
    trigger('slider', [
      state('open', style(
        {}
      )),
      state('closed', style(
        {}
      )),
      transition('closed => open', animate('0.4s ease-in')),
      transition('open => closed', animate('0.4s ease-out'))      
    ])
  ]

...

  @Input('state') state: string = 'closed';


  toggleState() {
    this.state = this.state === 'open' ? 'closed' : 'open';
  }

  openSidenav() {
    this.opened = true;
    this.aux = 0;
    this.toggleState();
  }

  closeSidenav() {
    if (this.opened) {
      this.opened = !this.opened;
      this.toggleState();     
    }
  }

....

my html

<div [@slider]="state" >
    <header> {{ navTitle }} </header>
    <i *ngIf="showCloseButton" class="iconic" (click)="closeSidenav()"></i>
    <ng-content></ng-content>
</div>

<div *ngIf="backdrop && opened" class="sidenav-backdrop"></div>

does not display any errors just does not apply the animation...Where am I going wrong?


Solution

  • My problem was in animation.

      animations: [
        trigger('slider', [
          state('open', style(
            {
              transform: 'translateX(0)'
            }
          )),
          transition('void => open', [
            style({transform: 'translateX(-100%)'}),
            animate(300)
          ]),   
          transition('open => void', [
            animate(100, style({transform: 'translateX(-100%)'}))
          ])
       ]