0
私は多くのテキストを表示するコンポーネントの展開/折りたたみアニメーションを試してみるために@angular/animations: 4.4.6
を使用しています。デフォルトでは一定量のテキストが表示されますが、異なる親コンポーネントで異なる畳み込み高さを定義することができます。
私が知ることから、私はすべてのことを正しくやっています。しかし、animations
デコレータは入力を無視し、デフォルト値に直接移動します。変数でアニメーションを作成する角度4
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" >
EDIT:(上記の)アニメーションで1の親<div>
が(click)="expandTex()"
属性を持っています。
_From私は、私は右のすべてをやって伝えることができるもの。 _この問題をstackblitzで再現してください。 –
@ RahulSingh:https://angular-mh66ap.stackblitz.ioアニメーションは機能していますが、折りたたまれた高さのデフォルト値に戻ります。 @Input()の中で。 – AvailableName