I'm beginner with angular 2 animations, and angular 2 by the way.
Actually I'm a bit confused because I cannot see anything about how to put all my animations into a single service, in order to reuse it through my components.
As far as I know, animations are defined inside the @component
. This makes me put it in all my components.
I fallow this article which uses a "factory" :
import {trigger, state, animate, style, transition} from '@angular/core';
export function routerTransition() {
return slideToLeft();
}
function slideToLeft() {
return trigger('routerTransition', [
state('void', style({position:'fixed', width:'100%'}) ),
state('*', style({position:'fixed', width:'100%'}) ),
transition(':enter', [ // before 2.1: transition('void => *', [
style({transform: 'translateX(100%)'}),
animate('0.5s ease-in-out', style({transform: 'translateX(0%)'}))
]),
transition(':leave', [ // before 2.1: transition('* => void', [
style({transform: 'translateX(0%)'}),
animate('0.5s ease-in-out', style({transform: 'translateX(-100%)'}))
])
]);
}
But in there is no @Injectable()
. Could any one give me an example of a true service I could put my animations in, then inject it in my components ?
Of course, this works, but I'd rather like to do it the Google way if it's possible, if there is a Google way to do it.
Thanks