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 sh
I've written a component that smoothly animates the height of projected content if that content changes. It's used like this:
{{content}}
Here's a stackblitz: https://stackblitz.com/edit/angular4-kugxw7
This is the component:
import {ElementRef, HostBinding, Component, Input, OnChanges} from '@angular/core';
import {animate, style, transition, trigger} from "@angular/animations";
@Component({
selector: 'smooth-height',
template: `
`,
styles: [`
:host {
display: block;
overflow: hidden;
}
`],
animations: [
trigger('grow', [
transition('void <=> *', []),
transition('* <=> *', [
style({height: '{{startHeight}}px', opacity: 0}),
animate('.5s ease'),
], {params: {startHeight: 0}})
])
]
})
export class SmoothHeightComponent implements OnChanges {
@Input()
trigger: any;
startHeight: number;
constructor(private element: ElementRef) {}
@HostBinding('@grow') get grow() {
return {value: this.trigger, params: {startHeight: this.startHeight}};
}
setStartHeight(){
this.startHeight = this.element.nativeElement.clientHeight;
}
ngOnChanges(){
this.setStartHeight();
}
}