title: How to start animation between routers after component's data is been load from a service
body: <p>I have a nice animation between my routes and I added a warp to every component to show the component only after the data has been loaded, it's look like this:</p>
  
  <p>my component HTML file:</p>
  
  <pre><code>&lt;div *ngIf="isDataAvailable"&gt;
     ...my component html template...
  &lt;/div&gt;
  </code></pre>
  
  <p>and this is my ts file:</p>
  
  <pre><code>isDataAvailable:boolean = false;
  ngOnInit() {
      this.subscription = this.clientsService.getClients().subscribe(
        (result:any) =&gt; {
          this.data = result.clients;
          this.isDataAvailable = true;
        }
      );
  }
  </code></pre>
  
  <p>in my root ts file I have this animation settings:</p>
  
  <pre><code>import { customTransition } from './custom-transition.animation';
  
  @Component({
    selector: 'app-master',
    templateUrl: './master.component.html',
    styleUrls: [
      './master.component.css',
    ],
    animations: [customTransition()],
    encapsulation: ViewEncapsulation.None
  })
  </code></pre>
  
  <p>and this is my HTML template for the root file</p>
  
  <pre><code>&lt;ng2-page-transition [animation]="customAnimation"&gt;
      &lt;div [@ng2ElementState]="customAnimation.state"&gt;
          &lt;router-outlet&gt;&lt;/router-outlet&gt;
      &lt;/div&gt;
  &lt;/ng2-page-transition&gt;
  </code></pre>
  
  <p>my issue right now is that some components are loading fast and some are loading slowly because of the data they have and this is fine but those that are loading slowly the user don't see the animation but just the component is shown when it is ready.</p>
  
  <p>I would like to start the animation after the data is beeing load
  maybe even to show some preloader for the user before the component is ready.</p>
  
  <p>thank you!</p>
  
  <p>EDIT:</p>
  
  <p>this is my customTransition.animation.ts file:</p>
  
  <pre><code>//custom-transition.animation.ts
  import {trigger, state, animate, style, transition, AnimationEntryMetadata} from '@angular/core';
  
  export function customTransition():AnimationEntryMetadata {
    return slideOutAndIn();
  }
  
  function slideOutAndIn():AnimationEntryMetadata {
    return trigger('ng2ElementState', [
      state('leave', style({
          position:'inherit', 
          display:'block',
          width:'100%'
      })),
      state('enter', style({
          position:'inherit', 
          display:'block',
          width:'100%'
      })),
      transition('* =&gt; enter', [
          style({
              transform: 'translateY(10%)',
              opacity: 0
          }),
          animate('0.5s ease-in-out', style({
              transform: 'translateY(0%)',
              opacity: 1
          }))
      ]),
      transition('* =&gt; leave', [
        style({
          transform: 'translateY(0%)',
          opacity: 0
        }),
        animate('0.5s ease-in-out', style({
          transform: 'translateY(-10%)',
          opacity: 0
        }))
      ]),
    ]);
  }
  </code></pre>