I've created the following animation in my Angular 4 project:
import { trigger, state, style, transition, animate } from '@angular/animations';
export function slide() {
return trigger('slide', [
transition('void => *', [
style({opacity: 0}),
style({transform: 'translateX(100%)'}),
animate('1s ease-in-out', style({transform: 'translateX(0%)', opacity: 1}))
]),
transition('* => void', [
style({opacity: 0}),
style({transform: 'translateX(100%)'}),
animate('1s 2s ease-in-out', style({transform: 'translateX(0%)', opacity: 1}))
])
])
}
I've attached the animation to my component using the host
property of the @Component
decorator.
@Component({
selector: 'test',
templateUrl: './test.component.html',
styleUrls: ['./test.component.scss'],
animations: [slide()],
host: {'[@slide]': '', 'style': 'display: block;'}
})
Now, I'd expect the animation to trigger at two points: 1. When the component is initialized, a.k.a when I hit the appropriate route 2. When I leave that route and navigate to another one
The first scenario works flawlessly, however the second one doesn't. What am I missing/doing wrong here?