我正在使用 @angular/animations: 4.4.6
尝试为一个组件添加展开/折叠动画,这个组件将显示大量的文本。默认情况下,它会显示一定量的文本,但是不同的父级组件可以定义不同的收起高度。
据我所知,我已经做到了一切正确。但是 animations
装饰器却忽略了输入,并直接使用了默认值。
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';
}
}
并且html代码为:<div [@expandCollapse]="{value: longTextState, min_height: minHeight}" [innerHtml]="textBody" >
为了完整起见需要说明:含有动画效果的那个父级<div>
带有一个属性(click)="expandTex()"
。