ngIf
这就变成了现实。
5px
50px
在里面
width
.
但是,一旦它结束了,它只是
成为全屏幕宽度!
这是这期杂志的复制品:
https://stackblitz.com/edit/angular-flf7ha
代码
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>
@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%'});
}
}