angular 2 在 *ng 中仅对一个元素进行动画处理

angular 2 animate in *ngFor only one element

我在*ngFor 中使用动画。当我点击并制作动画时,它会循环播放所有元素,但我只想制作一个动画。我怎样才能做到这一点 ? ..................................................... ..................................................... ..................................................... ...

   @Component({
    selector: 'app-popular-sensor',
    templateUrl: './popular-sensor.component.html',
    styleUrls: ['./popular-sensor.component.css'],
    animations: [
        trigger('focusPanel', [
            state('in', style({
                height: '20px'
            })),
            state('out', style({
                height: '*',
            })),
            transition('in => out', animate('400ms ease-in-out'))
        ])
    ]
})

export class PopularSensorComponent implements OnInit {

    goods;
    state = 'in';

    constructor(private goodsService: GoodsService) {
        goodsService.getGoods()
            .subscribe(goods => {
                this.goods = goods;
                console.log(this.goods);
            });
    }

    toggleChar() {
        this.state = this.state === 'in' ? 'out' : '';
    }

    ngOnInit() {

    }

}

html:

  <div *ngFor="let g of goods"
         class="col-sm-4 col-xs-12">
        <div class="sensor-block">

            <div class="char_block"
                 [@focusPanel]="state">
                <small *ngFor="let c of g.charact">{{c.name}}</small>
            </div>

            <div class="characteristic"
                 (click)="toggleChar()">Все характеристики смарт стола
            </div>
        </div>
    </div>

“key”不是使用全局变量,而是属于对象“g”的变量

<!--g.state-->
<div class="char_block" [@focusPanel]="g.state">
  <small *ngFor="let c of g.charact">{{ c.name }}</small>
</div>

<!--change g.state-->
<div class="characteristic" (click)="g.state=='in' ? 'out':'in'">
  Все характеристики смарт стола
</div>