gpt4 book ai didi

angular 2 动画在 *ng 中仅用于一个元素

转载 作者:行者123 更新时间:2023-12-03 23:55:31 26 4
gpt4 key购买 nike

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

http://joxi.ru/82QYVWGSjBRGM2

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

最佳答案

“键”不使用全局变量,而是属于对象“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>

关于angular 2 动画在 *ng 中仅用于一个元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49063983/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com