0
我在* ngFor循环中显示图像数组。当我知道<img> ID时,如何更改< img>的src?
itemimg.component.html
<div *ngFor="let itemimg of itemimgs" [class.selected]="itemimg === selectedItemimg"
(click)="onSelect(itemimg)">
<img id="{{itemimg.index}}" class="thumb" src="{{itemimg.imageUrl}}" width="{{itemimg.width}}" height="{{itemimg.height}}"
style="float: left; margin-right: 3px; margin-bottom: 3px">
</div>
当我点击任何我想要替换第一图像的图像。
itemimg.components.ts(部分)
onSelect(itemimg: Itemimg): void{
this.selectedItemimg = itemimg;
var newsrc = "../../assets/images/" + itemimg.route + ".jpg";
//alert (newsrc);
*what-goes-here* = newsrc; // the problem
}
我一直在GOOGLE上搜索这个了三个多小时,但无法找到答案。感谢您的期待。
当我看到您的回复我很尴尬,因为我应该能够为自己工作,但我确实尝试过。它工作完美,谢谢。 –