Список изображений в angular

#angular #image #ngfor

#angular #изображение #ngfor

Вопрос:

У меня есть массив, содержащий 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',
}
];
  

Комментарии:

1. вы ищете директиву *ngFor

Ответ №1:

Пожалуйста, проверьте приведенный ниже код, и вы можете использовать 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>