angular: RC4. Animation. void => * animation is not fired on component detach

I’m submitting a … (check one with “x”)

[ x] bug report
[ ] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior It looks like * => void animation is not fired when I try to detach a component through ViewContainerRef.detach().

I have the following animation defined for my component:

        trigger("appear", [
            transition('* => void', [
                style({ opacity: 1 }),
                animate(".2s cubic-bezier(0.25, 0.8, 0.25, 1)", style({opacity: 0}))
            ]),
            transition('void => *', [
                style({opacity: 0}),
                animate(".2s cubic-bezier(0.25, 0.8, 0.25, 1)", style({opacity: 1}))
            ])
        ])

I dynamically create the component using ViewContainerRef.createComponent() and entering animation works fine.

Then when I remove component using ViewContainerRef.detach() or ViewContainerRef.clear() leave animation is not fired.

Expected/desired behavior Leave animation is fired on ViewContainerRef.detach()

Environment:

  • Chrome: 52.0.2743.116
  • OS: Windows 10 + Anniversary Update
  • Angular: 2.0.0-rc4

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 5
  • Comments: 22 (6 by maintainers)

Most upvoted comments

Ok, I fixed your stuff https://plnkr.co/edit/nbLabGk2PoKiBoFNjGI4?p=preview %) Noticed host and where @enter moved? Right as in my example above. Meh. Can I go and drink today…

what’s happening here (I think, @matsko can correct me) is that the component you’re detaching is being detached before the nested animations have a chance to run.

This seems like a reasonable use case for using a host animation binding, as presumably you actually want to animate the container leaving. See https://plnkr.co/edit/XCNePBaccTN9q9wJSWxo?p=preview