Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

256
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!