state

在附加到元素的触发器上,声明一个动画状态。

Declares an animation state within a trigger attached to an element.

state(name: string, styles: AnimationStyleMetadata, options?: { params: { [name: string]: any; }; }): AnimationStateMetadata
      
      state(name: string, styles: AnimationStyleMetadata, options?: { params: { [name: string]: any; }; }): AnimationStateMetadata
    
参数
name string

所定义的状态的一个或多个名字(用逗号分隔)。 下面这些保留的状态名可用于为一些特殊用例定义样式:

One or more names for the defined state in a comma-separated string. The following reserved state names can be supplied to define a style for specific use cases:

  • void 你可以使用该名称关联一些样式,用于定义当该元素从应用中移除时的样式。比如,当 ngIf 的值为 false 时,相关元素的状态就是 void

    void You can associate styles with this name to be used when the element is detached from the application. For example, when an ngIf evaluates to false, the state of the associated element is void.

  • *(星号)表示默认状态。当触发器中未声明要设置的动画状态时,就会把该名称所关联的样式用作回退(fallback)值。

    * (asterisk) Indicates the default state. You can associate styles with this name to be used as the fallback when the state that is being animated is not declared within the trigger.

styles AnimationStyleMetadata

一组与该状态相关的 CSS 样式,使用 style() 函数创建。 一旦到达该状态,这组样式就会永久性的应用在该元素上。

A set of CSS styles associated with this state, created using the style() function. This set of styles persists on the element once the state has been reached.

options object

一些在调用它时可传给该状态的参数。 包含 0 或多个键值对。

Parameters that can be passed to the state when it is invoked. 0 or more key-value pairs.

可选. 默认值是 undefined.

返回值

一个封装了新状态数据的对象。

AnimationStateMetadata: An object that encapsulates the new state data.

使用说明

使用 trigger() 函数来为动画触发器注册状态。 使用 transition() 函数来在状态之间执行动画。 当某个状态在组件中激活时,它所关联的样式会永久性的作用在该元素上 —— 即使该动画已经结束了。

Use the trigger() function to register states to an animation trigger. Use the transition() function to animate between states. When a state is active within a component, its associated styles persist on the element, even when the animation ends.