Javascript 阵列中的角度2显示阵列
如果我有这个数组:Javascript 阵列中的角度2显示阵列,javascript,angular,typescript,Javascript,Angular,Typescript,如果我有这个数组: array = [ { img: [ {0: 'http://hairsalonfurniture.eu/wp-uploads/750x480_how-to-create-a-nice-hair-salon-s-reception-gjzd.jpg',}, {1: 'http://hairsalonfurniture.eu/wp-uploads/750x480_how-to-create-a-nice-hair-salon-s-recept
array = [
{
img: [
{0: 'http://hairsalonfurniture.eu/wp-uploads/750x480_how-to-create-a-nice-hair-salon-s-reception-gjzd.jpg',},
{1: 'http://hairsalonfurniture.eu/wp-uploads/750x480_how-to-create-a-nice-hair-salon-s-reception-gjzd.jpg',},
],
}
{
img: [
{0: 'http://hairsalonfurniture.eu/wp-uploads/750x480_how-to-create-a-nice-hair-salon-s-reception-gjzd.jpg',},
{1: 'http://hairsalonfurniture.eu/wp-uploads/750x480_how-to-create-a-nice-hair-salon-s-reception-gjzd.jpg',},
],
}
]
如何在HTML中显示它?我知道如何显示一个img,如果它是img:“url”,它看起来像这样
this.imgs = this.myprovider.getArray();
HTML:
<div ngfor="let item of imgs">{{item.img}}</div>
{{item.img}
试试看
{{item.img.toString()}
或
{{img}}
试试看
{{item.img.toString()}
或
{{img}}
您可以嵌套方式迭代两次-
<ng-container ngfor="let childImages of imgs">
<div ngfor="let item of childImages">{{item.img}}</div>
<ng-container>
{{item.img}
注意:您应该使用,而不是任何其他html元素,否则它将扭曲html的外观和感觉
可以嵌套方式迭代两次-
<ng-container ngfor="let childImages of imgs">
<div ngfor="let item of childImages">{{item.img}}</div>
<ng-container>
{{item.img}
注意:您应该使用,而不是任何其他html元素,否则它将扭曲html的外观和感觉
{{img[i]}
{{img[i]}
由于img
对象数组中的键是一个从0开始的数字,因此您可以使用循环索引访问该值:
<ul>
<li *ngFor="let item of array">
<ul>
<li *ngFor="let image of item.img; let i = index">
<img src="{{ image[i] }}" />
</li>
</ul>
</li>
</ul>
-
-
由于某些原因,Stack Blitz不想加载图像URL,但正如您从输出中看到的,HTML是正确的:由于
img
对象数组中的键是一个从0开始的数字,因此您可以使用循环索引访问该值:
<ul>
<li *ngFor="let item of array">
<ul>
<li *ngFor="let image of item.img; let i = index">
<img src="{{ image[i] }}" />
</li>
</ul>
</li>
</ul>
-
-
由于某些原因,Stack Blitz不想加载图像URL,但正如您从输出中看到的,HTML是正确的:我自己在提供程序中编写的,因此我不确定其是否有效,0个错误。我自己在提供程序中编写的,因此不确定其是否有效,0个错误。找不到类型为“string”的不同支持对象“”。NgFor只支持绑定到Iterables,如ArrayS。您是否看过StackBlitz示例?它使用您的示例数据。只能将ngFor绑定到支持迭代(循环)的值。如果您实际使用的数据与您的问题不匹配,您需要更新您的问题。顺便说一句,您的示例数据在
数组
对象之间缺少逗号,这在示例中是固定的。这与问题相同,我在数组中有2个URL。找不到类型为“string”的不同支持对象“”。NgFor只支持绑定到Iterables,如ArrayS。您是否看过StackBlitz示例?它使用您的示例数据。只能将ngFor绑定到支持迭代(循环)的值。如果您实际使用的数据与您的问题不匹配,您需要更新您的问题。顺便说一句,您的示例数据在数组
对象之间缺少一个逗号,这在示例中是固定的。这与问题相同,我在数组中有两个URL。“,”在对象数组中缺少。“,”在对象数组中缺少。
<ul>
<li *ngFor="let item of array">
<ul>
<li *ngFor="let image of item.img; let i = index">
<img src="{{ image[i] }}" />
</li>
</ul>
</li>
</ul>