我正在尝试为投资组合构建一些有意义的议案。目标是当用户点击工作项目时,该项目弹出并成长。要做到这一点,我相信我必须改变数组内部点击元素的状态,但是现在当我点击它时,它会影响数组内部所有元素的所有状态,这些状态都是一起动画的。任何人都可以解释我发生了什么以及如何解决?Angular 2/4为数组内的一个项目添加动画而不是所有项目
portfolio.component.ts
import { Component } from '@angular/core';
import { trigger,style,transition,animate,keyframes,state,query,stagger } from '@angular/animations';
export class Job {
id: number;
title: string;
}
const JOBS: Job[] = [
{ id: 11, title: 'Item 1' },
{ id: 12, title: 'Item 2' },
{ id: 13, title: 'Item 3' },
];
@Component({
selector: 'portfolio',
templateUrl: './portfolio.component.html',
styleUrls: ['./portfolio.component.css'],
animations: [
trigger('enlarge', [
state('small', style({
height: '100px',
})),
state('large', style({
height: '200px',
background: 'red',
})),
transition('small <=> large',
animate('1s ease-in')),
]),
]
})
export class PortfolioComponent {
title = 'Portfolio';
jobs = JOBS;
state: string = 'small'
enlarge() {
this.state = (this.state === 'small' ? 'large' : 'small');
}
}
portfolio.component.html
<div class="list"
*ngFor='let job of jobs'
[@enlarge]='state'
(click)="enlarge()">
<div for="#">{{job.id}} - {{job.title}}</div>
</div>
感谢您快速的答案,但我应该在哪里把步骤1中的代码?我试图把它放在我的课堂上,但我收到一个错误:意外的令牌。期望构造函数,方法,访问器或属性。 –
尝试更新的代码@OsmarMatos。把它放在你得到你的工作清单之后.. – TheUnreal
尝试过,但现在错误属性'状态'不存在类型'作业'在屏幕上和Uncaught TypeError:无法读取控制台上未定义的属性'地图' - @ TheUnreal –