Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

217
Vistas
How to start animation between routers after component's data is been load from a service

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:

my component HTML file:

<div *ngIf="isDataAvailable">
   ...my component html template...
</div>

and this is my ts file:

isDataAvailable:boolean = false;
ngOnInit() {
    this.subscription = this.clientsService.getClients().subscribe(
      (result:any) => {
        this.data = result.clients;
        this.isDataAvailable = true;
      }
    );
}

in my root ts file I have this animation settings:

import { customTransition } from './custom-transition.animation';

@Component({
  selector: 'app-master',
  templateUrl: './master.component.html',
  styleUrls: [
    './master.component.css',
  ],
  animations: [customTransition()],
  encapsulation: ViewEncapsulation.None
})

and this is my HTML template for the root file

<ng2-page-transition [animation]="customAnimation">
    <div [@ng2ElementState]="customAnimation.state">
        <router-outlet></router-outlet>
    </div>
</ng2-page-transition>

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.

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.

thank you!

EDIT:

this is my customTransition.animation.ts file:

//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('* => enter', [
        style({
            transform: 'translateY(10%)',
            opacity: 0
        }),
        animate('0.5s ease-in-out', style({
            transform: 'translateY(0%)',
            opacity: 1
        }))
    ]),
    transition('* => leave', [
      style({
        transform: 'translateY(0%)',
        opacity: 0
      }),
      animate('0.5s ease-in-out', style({
        transform: 'translateY(-10%)',
        opacity: 0
      }))
    ]),
  ]);
}
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

the animation should be inside the component and not in the root file, so this is my result:

import {trigger, state, animate, style, transition, AnimationEntryMetadata} from '@angular/core';

@Component({
  selector: 'app-clients',
  templateUrl: './clients.component.html',
  styleUrls: ['./clients.component.css'],
  animations: [trigger('slideIn', [
    state('inactive', style({
        transform: 'translateY(10%)',
            opacity: 0
    })),
    state('active', style({
        transform: 'translateY(0%)',
            opacity: 1
    })),
    transition('active => inactive', animate('.6s ease')),
    transition('inactive => active', animate('.6s ease'))]
  ]
})

export class ClientsComponent implements OnInit,OnDestroy {
  state:string = "inactive";

  constructor( private clientsService: ClientsService) {}

  ngOnInit() {
    this.updateData();
  }

  updateData(){
    this.subscription = this.clientsService.getClients().subscribe(
      (result:any) => {
        this.data = result.clients;
        this.state = "active";
      }
    );
  }
}
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda