【问题标题】:Angular2 animate event emitter removal of child componentAngular2动画事件发射器删除子组件
【发布时间】:2017-02-20 16:35:39
【问题描述】:

我有一个使用事件发射器移除的子组件,我想在移除时添加动画。我的想法是从通配符状态动画到无效:

@Component({
  selector: 'content-attendee',
  styleUrls: ['content-attendee.component.scss'],
  template: `
    <div class="px1 item">
      testing 123
         <a class="btn-remove ion-close-circled md fnt--mid-gray" (click)="handleRemoval()"></a>
      </div>
    </div>
  `,
    animations: [
      trigger('item', [
        transition('* => void', [
          animate(100, style({ transform: 'scale3d(0, 0, 0)' }))
        ])
      ])
    ]

})

export class ContentAttendeeComponent { 
  @Input() contentAttendee: AttendeeModel;

  @Output()
  delete: EventEmitter<AttendeeModel> = new EventEmitter<AttendeeModel>();

  handleRemoval(contentAttendee: AttendeeModel) {
      this.delete.emit(this.contentAttendee);
  }
}

但是移除动画没有运行,非常感谢任何帮助。

【问题讨论】:

    标签: angular angular2-template web-animations


    【解决方案1】:

    您还可以使用 :leave 代替 * =&gt; void 作为休假别名。也尝试添加:enter 转换并可能添加到其他状态。虽然在模板中指定 [@item] 应该可以工作。

    触发器

     animations: [
          trigger('item', [
            transition(':leave', [
              animate(100, style({ transform: 'scale3d(0, 0, 0)' }))
            ])
          ])
        ]
    

    模板

    <div class="px1 item" [@item]="animationtrigger"> // remove "animationtrigger" just use [@item]
      testing 123
         <a class="btn-remove ion-close-circled md fnt--mid-gray" (click)="handleRemoval()"></a>
      </div>
    </div>
    

    export class ContentAttendeeComponent { 
    
          @Input() contentAttendee: AttendeeModel;
          animationtrigger:bool; // just to make sure a transition is firing
    
          @Output()
          delete: EventEmitter<AttendeeModel> = new EventEmitter<AttendeeModel>();
    
          handleRemoval(contentAttendee: AttendeeModel) {
              this.delete.emit(this.contentAttendee);
              this.animationtrigger=true; // remove this line eventually
          }
        }
    

    【讨论】:

    • 感谢您的帮助,事实证明 * => void 动画状态没有被触发,我最终将其更改为:'* => inactive'
    猜你喜欢
    • 1970-01-01
    • 2017-03-07
    • 2017-02-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-01
    相关资源
    最近更新 更多