How to interpolate in Angular animation

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

I get an error saying that "Expected expression, got interpolation"

2

There are 2 best solutions below

0
On BEST ANSWER

Brackets [] expect a expression, e.g. something like states.obj.key, whereas on normal attributes you have to use interpolation {{}} to insert an expression.

I think what you meant to write is either

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

or

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

0
On

<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>