如何在Angular动画中进行插值

问题描述

<ng-container *ngFor="let obj of mainData | keyvalue">
   <span [@animate]="states.{{obj.key}}">
      //////////////////////////////
   </span>
</ng-container>

我收到一条错误消息,说“期望的表达式,已插入”

解决方法

括号[]需要一个表达式,例如类似于states.obj.key,而在普通属性上,您必须使用插值{{}}来插入表达式。

我想你想写的是

[@animate]="states[obj.key]"

@animate="{{ states[obj.key] }}"

,

<ng-container *ngFor="let obj of mainData | keyvalue">
   <span [@animate]="states.{{obj.key}}">
        code
   </span>
</ng-container>

or

<ng-container *ngFor="let obj of mainData | keyvalue">
   <span [@animate]="states.[obj.key]">
        code
   </span>
</ng-container>