我想根据数组索引显示图像,但是它显示的是内容不同的随机图像。
我的代码.ts文件
for (let i = 0; i < this._robots.length; i++) {
this.posts1 = this._robots[i].AttachmentFiles;
console.log("this.posts1",this.posts1+"");
for (let j = 0; j < this.posts1.length; j++) {
this.array = this.posts1[j]["odata.id"];
this.getImage(this.array).subscribe(res =>{
let b: any = new Blob([res], { type: 'application/octet-stream' });
var url = window.URL.createObjectURL(b);
console.log("this is url bro"+url);
console.log(this.photoPicArray);
this.photoPicArray.push(url);
});
console.log("this is array url of 1234 images",this.photoPicArray+"");
}
}
在HTML文件中
<ion-slides #slider (ionDidChange)="SlideChanged()" [options]="_sliderOptions" id="ionSlider" class="main-slider">
<ion-slide #slide *ngFor="let robot of _robots; let i = index ">
<ion-grid class="content-info-item">
<img [src]="sanitizer.bypassSecurityTrustResourceUrl(photoPicArray[i])" class="postimage" />
<!-- <div class="postimage" attr.id="Testing{{i}}"></div> -->
<div class="content-info-content">
<p class="posttime">Time of post</p>
<h1 class="GuardianEgyp-Regular-Web heading-title" (click)="goToLongStory(i)">{{robot.Title}}</h1>
<p class="shortstory GuardianEgyp-Light-Web" (click)="goToLongStory(i)">{{robot.SortStory}}</p>
</div>
</ion-grid>