This is my first try at any angular animation. My aim is to simply animate an li when it is removed from the list. I think I'm calling everything right, but it seems to be animating all the li items, instead of just the one deleted. Do I need to get a reference to a "this li" some how? (this also happens when I try to animate an added li, it effects all other li.)
component
@Component({
selector: 'to-do',
templateUrl: './to-do.component.html',
styleUrls: ['./to-do.component.css'],
animations: [
trigger('flyOut', [
state('hide', style({
opacity: 0,
transform: 'translateX(-100%)'
})),
transition( '* => *', [animate(500)] )
])
]
}) //end of @component
export class ToDoComponent implements OnInit {
animationState: string;
newTodo: string;
todos: any;
constructor() {
}
addTodo(event) {
// bla bla
}
deleteTodo(i, name:string) {
this.animationState = name;
this.todos.splice(i, 1);
this.setLocalStorageTodos(this.todos);
}
and html
<ul id="todo-list">
<li class="search-item" [@flyOut]="animationState" *ngFor="let todoItem of todos; let i=index ">
<span class="todo-item">{{ todoItem }}</span>
<span class="delet-todo" (click)="deleteTodo(i, 'hide')">✕</span>
</li>
I thought this would be easy... haha