angular - Angular2: Delete element from the list animation -


i have simple list (tasks) cards (task). when delete task, confirmation dialog called. if user confirms deletion, http call made. if it's successful variable isdeleted set true , send list item toggling class. here encounter few problems:

  1. if click on item , not delete (on confirmation choose 'no'), , click on item , delete - both of these items class (why? id's different).

    <div class="vb-task-card" [ngclass]="{'vb-deleted': task.id === selecteditemid && isdeleted}">   // here comes rest of layout    <button (click)="ondeletetask(task)"> delete</button> </div> 

if user clicks on button following function called:

    public ondeletetask(task) {        this.selecteditemid = task.id;        this.deletetask.emit(task);     } 
  1. how add fade out animation item delete?

p.s. if need more code or full code - let me know!

thanks in advance!

so, i've figured out. isdeleted setted on elements in *ngfor. should have property on object, this: task.deleted = true , work that.

what animations, followed official documentation.

here code:

import {component, input, output, eventemitter,     trigger,     state,     style,     transition,     animate} "@angular/core";  @component({ selector: "vb-tasks-item", animations: [     trigger('taskstate', [         state('inactive', style({opacity: 1, transform: 'translatex(0) scale(1)'})),         state('active',   style({opacity: 1, transform: 'translatex(0) scale(1)'})),         state('void',   style({opacity: 0, display: 'none', transform: 'translatex(0) scale(1)'})),         transition('* => void', [             animate('1s 8 ease-out', style({                 opacity: 0,                 transform: 'translatex(0) scale(0.5)'             }))         ])     ]) ], template: ` <div class="vb-task-card" @taskstate="task.deleted"> </div>`  export class tasksitemcomponent {    @input() public task: tasksummary;     @output() public deletetask = new eventemitter();     public ondeletetask(task) {       task.deleted = (task.deleted === 'active' ? 'inactive' : 'active');       this.deletetask.emit(task);    }  } 

i'm setting animation state (task.deleted) if user confirms deletion:

public ondeletemodal(isok) {     this.ismodalopen = isok;     if(isok) {         this.taskssandbox.deletetask(this.tasktodelete.id)             .subscribe(res => {                 if (res) {                     this.tasktodelete.deleted = 'void';                     this.ismodalopen = !isok;                 }             });     }else{         this.tasktodelete.deleted = 'inactive';     } } 

Comments

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -