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

254
Vistas
update @HostBinding Angular 4 Animation

I am trying to get animation between routes working in an Angular 4 project - but need to be able to alter the direction of the animation (translateX) based on the way the user is navigating through the app.

I have discovered that the only way to keep both the entering and exiting components in the DOM is to use void state.

Also, I have to bind the animation to the host element. If I try and bind it to an element within the component the exiting component is just replaced with the entering component.

I want this because I don't want the exiting component to disappear - I want it to slide off as the entering component slides in to get a smooth native feeling application.

I have a single trigger set up with four transitions:

trigger('routing',[
    state('*',style({transform: 'translateX(0)'})),
    transition('void => back',[
        style({transform: 'translateX(-100%'}),
        animate('800ms')
    ]),
    transition('back => void',[
        animate('800ms',style({
            transform:'translateX(100%)'
        }))
    ]),
    transition('void => forward',[
        style({transform: 'translateX(100%'}),
        animate('800ms')
    ]),
    transition('forward => void',[
        animate('800ms',style({
            transform:'translateX(-100%)'
        }))
    ])
])

In my components exported class I am binding this to the component host elements with:

@HostBinding('@routing') routing

I can manipulate routing (setting it to either 'back' or 'forward' to control direction) but this seems to create a new instance of the variable so that if I want to change animation direction the exiting page animates in the opposite direction to the incoming component because the instance of routing doesn't seem to have changed.

Is there any way to update the instance of routing bound to the host element? Is there an alternative way to achieve the result I need?

Thanks.

about 4 years ago · Santiago Trujillo
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