角度4动画到高度*

时间:2017-04-10 20:33:31

标签: angular animation wildcard angular-animations

我一直对一些我认为是Angular 4动画模块中的错误感到困惑。通过Angular 2.x中的动画,我制作了一个动画,从高度*动画到固定高度。这在Angular 2中运行得非常好。另一方面,当使用Angular 4时,在动画完成之前重新触发动画时,应用动画的元素的高度会出错。通配符(*)高度似乎是导致问题的原因。这是一个可以重现问题的演示片段。如果在元素处于* -height状态时双击该元素,则可以触发该错误:

import { Component } from '@angular/core';
import { trigger, animate, state, transition, style } from '@angular/animations';

@Component({
  selector: 'app-root',
  template: `
  <h1 [@toggleAnimation]="isEnabled" (click)="isEnabled = isEnabled === 'active' ? 'inactive' : 'active'" style="background: blue">
    {{title}}
  </h1>`,
  animations:
  [
    trigger('toggleAnimation', [
      state('active', style({
        height: '*',
      })),
      state('inactive', style({
        height: '600px',
      })),
      transition('active <=> inactive', animate('500ms ease-in-out'))
    ])
  ]
})
export class AppComponent {
  title = 'app works!';
  isEnabled = 'inactive';
}

使用通配符值如何设置高度动画是否有问题,或者通配符高度的表现方式是否有问题?

1 个答案:

答案 0 :(得分:3)

似乎是一个错误:https://github.com/angular/angular/issues/15507

显然!是一个秘密&#39; 4.2.0-rc.1中的值似乎可以解决问题,但这似乎不是正式支持或将在官方发布中支持的内容。

https://plnkr.co/edit/pZamSqPX9Vb4J6JL721u?p=preview显示4.2.0-rc.1!合作,然后转到config.js并更改为4.0.0并更改!*再看看它是怎么回事。