首页 > 解决方案 > 角度图像列表

问题描述

我有一个包含 src 和标题的数组。我需要在通过数组循环的列表中显示图像。

IMAGES = [
{
  src: 'https://material.angular.io/assets/img/examples/shiba2.jpg',
  caption: 'It\'s a thing',
},
{
  src: 'https://picsum.photos/200',
  caption: 'This is a really long string to see how the text will overflow',
},
{
  src: 'https://picsum.photos/200',
  caption: 'It\'s a thing',
},
{
  src: 'https://picsum.photos/200',
  caption: 'It\'s a thing',
},
{
  src: 'https://picsum.photos/200',
  caption: 'It\'s a thing',
},
{
  src: 'https://picsum.photos/200',
  caption: 'It\'s a thing',
}
];

标签: angularimagengfor

解决方案


请检查以下代码,您可以使用 div 和内部 div img 标签。

<div *ngFor="let image of IMAGES">
    <img [src]="image.src" [attr.alt]="image.caption" [attr.title]="image.caption" width="100" height="100">
</div>

推荐阅读