Demo
There are multiple issues.
The first one is that you are trying to animate <tr>
tags, I don't recommend to do this since the generated dom is different than the template.
So I switched to basic <div>
tags to fix this.
The second is that your array is never empty, that's why there is no leave animation.
So I set its value to an empty array for an instant using the setTimeout
function.
setInterval(() => {
this.items = [];
setTimeout(() => {
this.items = this.i++ % 2 == 0 ? ["1", "2", "3"] : ["x", "y", "z"];
}, 0);
}, 3000);
The third issue is that the animations are not synced, so I have to add a delay to the stagger animation in order to sync it.
I also did various tweaks to the animation to make it look good.
animations: [
trigger("listAnimation", [
transition("* => *", [
// each time the binding value changes
group([
query(
":leave",
[stagger(100, [animate("0.5s", style({ opacity: 0 }))])],
{ optional: true }
),
query(
":enter",
[
style({ opacity: 0, height: 0, visibility: 'hidden' }),
stagger(100, [
animate("0s 1.5s", style({})),
style({ height: "*", visibility: 'visible' }),
animate(".5s", style({ opacity: 1 }))
])
],
{ optional: true }
)
])
])
])
],
NB: there are still errors throwing in the console that I have yet to figure out.