Reputation: 1398
I use animation in *ngFor. When i click and do animation, it animate all elements in cycle, but I want animate only one. How can I do that ? .........................................................................................................................................................
@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>
Upvotes: 4
Views: 2138
Reputation: 57981
the "key" is not use a global variable, instead a variable belong to the object "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>
Upvotes: 3