Angular 角度显示阵列中的所有图像
我想在“image\u url”数组中显示这些图像。 我使用循环,但图像不可见Angular 角度显示阵列中的所有图像,angular,typescript,Angular,Typescript,我想在“image\u url”数组中显示这些图像。 我使用循环,但图像不可见 Array - image_url: [ 0: "https://xyz/16183424594601618342458.5021539.jpg" 1: "https://xyz/16183424594701618342458.579036.jpg" 2: "https://xyz/16183424594511618342458.4947538.jpg"
Array -
image_url: [
0: "https://xyz/16183424594601618342458.5021539.jpg"
1: "https://xyz/16183424594701618342458.579036.jpg"
2: "https://xyz/16183424594511618342458.4947538.jpg"
3: "https://xyz/16183424594661618342458.566865.jpg" ]
this.postImages = res.data.postdata.image_url;
<div class="" *ngFor="let images of postImages">
<div class="flex items-center justify-between">
<div class="items-center py-4">
<img class="side-image w-56 h-56 mr-4 bg-cover bg-no-repeat border"
[src]="images ? images : './assets/profile.svg'">
</div>
</div>
</div>
数组-
图片地址:[
0: "https://xyz/16183424594601618342458.5021539.jpg"
1: "https://xyz/16183424594701618342458.579036.jpg"
2: "https://xyz/16183424594511618342458.4947538.jpg"
3: "https://xyz/16183424594661618342458.566865.jpg" ]
this.postmages=res.data.postdata.image\u url;
有人能解释一下我做错了什么吗?我可能错了,但看起来数组中的第一项是数值,第二项是实际url,您是否尝试过使用图像[1]。您可以通过查看编译后的html来验证这一点,查看它为src打印出了什么?当我添加I=index时,它得到了解决
<div class="" *ngFor="let images of postImages; let i = index">
请将变量声明为字符串数组或下面提到的任何变量 公开帖子:有吗 公共后映像:字符串[]
可能是声明存在问题,否则代码会正常工作。您的代码似乎正确,请确保图像链接正常工作。有时在处理url字符串时,您需要对其进行清理,您是否收到任何错误或警告?@HenrikBøgelundLavstsen没有错误或警告。很可能是复制
console.log
语句的输出的产物。大多数浏览器都会打印带有相应索引的数组。没错,我同意你的意思。我不相信这是真正修复它的方法。你还改变了什么吗?