![](/img/trans.png)
[英]how to loop the dynamically nested array using ngFor in angular 7
[英]How to dynamically call all the images and display using *ngFor in Angular?
我正在嘗試使用*ngFor
顯示資產文件夾中的許多圖像
* .TS
this.assetsImages = ['12.jpg', 'tt.jpg', 'an.jpg', 'pn.png'];
html的
<div *ngFor="let image of assetsImages" >
<img src="../../assets/{{image}}" height="100px" width="100px" >
</div>
在上面,我靜態地寫了要顯示的圖像的路徑。 但是,如果我有大量的圖像,則需要對所有路徑進行硬編碼,這是不可行的。
有沒有其他替代方法可以動態顯示所有圖像?
您無法使用前端做到這一點。 您需要使用后端並在其中返回文件。
嘗試這個
.TS
this.assetsImages = ['../../assets/12.jpg', '../../assets/tt.jpg', 'an.jpg', '../../assets/pn.png'];
HTML
<div *ngFor="let image of assetsImages" >
<img [src]="image" height="100px" width="100px" >
</div>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.