I've created an Angular animation (please see Stackblitz link below). I want an element to animate on entry, when the condition of the ngIf
that wraps it becomes true.
The animation works at the beginning, expanding from 5px
to 50px
in width
.
But then, once it reaches the end, it just jumps to become full screen width!
Here is a reproduction of the issue: https://stackblitz.com/edit/angular-flf7ha
The code
app.component.html
<button (click)="addBars()">Toggle Bar</button>
<div *ngFor="let bar of bars">
<div id="bar" @horizontalBarGrow [style.width.%]="bar.width"></div>
</div>
app.component.ts
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ],
animations: [
trigger('horizontalBarGrow', [
transition(':enter', [
style({ width: '5px' }),
animate('500ms ease-out', style({ width: '50px' })),
]),
])
]
})
export class AppComponent {
name = 'Angular';
bars = []
addBars() {
this.bars.push({ width: '10%'});
this.bars.push({ width: '40%'});
}
}