I'm using @angular/animations: 4.4.6
to try and have an expand/collapse animation for a component that will display lots of text. As a default it will display a certain amount of text, but different parent components can define a different collapse height.
From what I can tell, I'm doing everything right. But the animations
decorator is ignoring the input, and going directly for the default value.
import { AUTO_STYLE, trigger, state, style, transition, animate, keyframes } from '@angular/animations';
@Component({
selector: 'app-long-text',
templateUrl: './long-text.component.html',
styleUrls: ['./long-text.component.scss'],
animations: [
trigger('expandCollapse',[
state('collapsed, void', style({
height: '{{min_height}}',
}), {params: {min_height: '4.125em'}}),
state('expanded', style({
height: AUTO_STYLE
})),
transition('collapsed <=> expanded', animate('0.5s ease'))
])
]
})
export class LongTextComponent implements OnInit {
@Input() minHeight: string;
@Input() textBody: string;
longTextState: string = 'collapsed';
constructor() {
}
ngOnInit() {
}
expandText(){
this.longTextState = this.longTextState === 'expanded' ? 'collapsed' : 'expanded';
}
}
And the html: <div [@expandCollapse]="{value: longTextState, min_height: minHeight}" [innerHtml]="textBody" >
EDIT for completeness sake: the parent <div>
of the one with the animation (mentioned above) has a (click)="expandTex()"
attribute.
Working LINK