Angular 2 Animation - bool 触发器?

标签 angular typescript angular2-animation

我试图触发绑定(bind)到 bool 属性的转换,但这似乎没有触发。

这是我的动画触发器的简化版本

trigger(
  'trueFalseAnimation', [
    transition('* => true', [
      style({backgroundColor: '#00f7ad'}),
      animate('2500ms', style({backgroundColor: '#fff'}))
    ]),
    transition('* => false', [
      style({backgroundColor: '#ff0000'}),
      animate('2500ms', style({backgroundColor: '#fff'}))
    ])
  ]
)

HTML:

<div [@trueFalseAnimation]="model.someProperty">Content here</div>

测试:

ngOnInit() {

    setTimeout(() => {
        this.model.someProperty = true;
        setTimeOut(() => {
            this.model.someProperty = false;
        }, 5000);    
    }, 1000)
}

someProperty 改变时触发永远不会发生。

作为快速测试,我将触发器更改为使用字符串并且它有效

trigger(
      'trueFalseAnimation', [
        transition('* => Success', [
          style({backgroundColor: '#00f7ad'}),
          animate('2500ms', style({backgroundColor: '#fff'}))
        ]),
        transition('* => Failed', [
          style({backgroundColor: '#ff0000'}),
          animate('2500ms', style({backgroundColor: '#fff'}))
        ])
      ]
    )

测试:

ngOnInit() {

    setTimeout(() => {
        this.model.someProperty = "Success";
        setTimeOut(() => {
            this.model.someProperty = "Failed";
        }, 5000);    
    }, 1000)
}

第二个例子很好用

我的问题是

  1. 是否支持 bool 值作为触发器?
  2. 如果对#1 是,我是什么 做错了吗?

最佳答案

  1. 好像没有。我看到一个问题 ( 12337 ) 已经被提出 为此,但到目前为止还没有更新。
  2. 另一种选择是使用 1 和 0 而不是 true 和 false。

参见 plunker来自 here .

trigger('isVisibleChanged', [
      state('true' , style({ opacity: 1, transform: 'scale(1.0)' })),
      state('false', style({ opacity: 0, transform: 'scale(0.0)'  })),
      transition('1 => 0', animate('300ms')),
      transition('0 => 1', animate('900ms'))
])

关于Angular 2 Animation - bool 触发器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40340919/

相关文章:

angular - 如何从 mockStore.overrideSelector() 重新分配值?

javascript - 如何在 TypeScript 中添加索引签名

typescript - 告诉 TypeScript 使用另一个模块的类型来使用不同名称的当前模块

Angular 4 动 Canvas 尔触发器

angular - 参数更改时在组件上触发动画

css - 如何以 2/4 Angular 为动画状态赋予类名?

javascript - @ngrx 从数组中返回一个带有 .single 的对象

angular - 动态更改 Angular 12 中垫子对话框的宽度/高度

javascript - ng build --aot : ERROR in : Unexpected directive 'TooltipComponent in 的意外结果

javascript - 迭代 TypeScript 中的接口(interface)属性