Angular 2 RC 4 New Animations not supported in Directives
See original GitHub issueHi,
It seems that in current release we can add animations to components only and cannot define them as directives. I mean:
the below works
@Component({
selector: "animate-demo",
animations: [
trigger('openClose', [
state('closed, void',
style({ height: "0px" })),
state('open',
style({ height: "*" })),
transition("* => *", animate(200))
])
]
})
Whereas the below doesn’t work:
@Directive({
selector: "animate-demo",
animations: [
trigger('openClose', [
state('closed, void',
style({ height: "0px" })),
state('open',
style({ height: "*" })),
transition("* => *", animate(200))
])
]
})
And gives compilation error in visual studio:
"Argument of type ‘{ selector: string; animations: AnimationEntryMetadata[]; template: string; }’ is not assignable to parameter of type ‘{ selector?: string; inputs?: string[]; outputs?: string[]; properties?: string[]; events?: strin…’.
"
Usually we might want to have the commonly used animations such as slideDown, sliddeUp, fadeIn, fadeOut defined at one place as a directive and then in components where we want to use them we would just want to import the directive and use the animation instead of redefining animation in each component.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:67
- Comments:33 (12 by maintainers)
Even though directives are not attached to a view, they should still be able to place animations on the host element that they are attached to.
Say for example you wanted to create a directive to manipulate
animate.css
animations:(The use of using CSS classes/keyframes within
animate
will be possible once the CSS parser is integrated. The example above is just to show how useful it can be to make a directive that manages animations.)As a workaround you can create
animations.ts
file like:And then use it in components like: