【发布时间】:2019-10-16 09:59:37
【问题描述】:
我试图在 2 秒内全部显示图像,但我设法先全部显示出来。
这是我的 HTML 行:
<img id="bh" routerLink="/" *ngIf="bh?.id == count" [src]="bh?.src" height="42" width="42"/>
还有我的 .ts 方法:
Timer(){
setInterval(() => {
this.count=this.count++
}, 2000)
}
与:
export class HeaderComponent implements OnInit{
count=0
BHs = [
new Bh (1, "assets/img/photo_bonhommes/BH1.jpg.png"),
new Bh (2, "assets/img/photo_bonhommes/BH2.png"),
new Bh (3, "assets/img/photo_bonhommes/BH3.png"),
new Bh (4, "assets/img/photo_bonhommes/BH4.png"),
new Bh (5, "assets/img/photo_bonhommes/BH5.png"),
new Bh (6, "assets/img/photo_bonhommes/BH6.png"),
new Bh (7, "assets/img/photo_bonhommes/BH7.png"),
new Bh (8, "assets/img/photo_bonhommes/BH8.png"),
new Bh (9, "assets/img/photo_bonhommes/BH9.png"),
new Bh (10, "assets/img/photo_bonhommes/BH10.png"),
new Bh (11, "assets/img/photo_bonhommes/BH11.png"),
];
}
顺便说一句,它是用 *ngFor 显示的,但我想我必须在这里使用 *ngIf ..
我也试过了:
<img id="bh" routerLink="/" *ngIf="bh?.id == this.count" [src]="bh?.src" height="42" width="42"/>
但不工作..非常感谢!
【问题讨论】:
-
bh来自哪里? -
this.count应该是count,但我认为更改不会解决您的问题。 -
对不起,我会添加它
-
好的,谢谢@TheNsn666,这是第一次帮助