I've successfully gotten a panel to animate expanding and closing when entering and leaving the DOM. The problem is I now have a busy indicator inside the panel prior to showing details, and the animation only occurs for opening the busy indicator, and snaps when the detail content is shown.
How can I get the Angular animation to animate on any height change?
I have an example here: https://plnkr.co/edit/Bs0rwp4ElidR75zN3ulR
trigger('expandCollapseDetails', [
state('void', style({
'height': '0px',
overflow: 'hidden'
})),
//element being added into DOM.
transition(':enter', [
animate('500ms ease-in-out', style({
'height': '*',
overflow: 'hidden'
}))
]),
//element being removed from DOM.
transition(':leave', [
animate('500ms ease-in-out', style({
'height': '0px',
overflow: 'hidden'
}))
])
])
I made a directive based on @MartinCremer answer. I think using a directive makes more sense since by doing that, you also should add the animation to your parent component (and it's close the standard way of adding animations).
So inside my
animations.ts
file. I've added the animation:then you should add this animation to your parent component (the component that you want to use the animation inside it):
And here is the directive which is really close to the component of @MartinCremer:
Finally inside
parent.component.html
use the directive:Just replace
yourAnimationIndicator
with the variable that the animation should trigger on change of its value.I've written a component that smoothly animates the height of projected content if that content changes. It's used like this:
Here's a stackblitz: https://stackblitz.com/edit/angular4-kugxw7
This is the component:
You can achieve something similar with a bit of css and js:
Solution:
component.ts
css
Code:
https://stackblitz.com/edit/angular-il71da