Typescript 如何更改an的src<;img>;当我知道了<;img>;身份证件?

Typescript 如何更改an的src<;img>;当我知道了<;img>;身份证件?,typescript,angular2-components,Typescript,Angular2 Components,我以*ngFor循环显示一组图像 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}}"

我以*ngFor循环显示一组图像

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>

我已经被谷歌搜索了三个多小时,但找不到答案。谢谢您的查看。

您想替换数组
itemimgs
中第一个图像的
imageUrl

所以你只需要

this.itemimgs[0].imageUrl = newsrc;

考虑到您始终希望替换阵列中的第一个映像,请执行以下操作:

onSelect(itemimg: Itemimg): void{ 
this.selectedItemimg = itemimg;
var newsrc = "../../assets/images/" + itemimg.route + ".jpg";
//alert (newsrc);
this.itemimgs[0].imageUrl = newsrc;  

}

我一看到你的答复就感到很尴尬,因为我本来可以自己解决这个问题的,但我确实试过了。非常好,谢谢。
onSelect(itemimg: Itemimg): void{ 
this.selectedItemimg = itemimg;
var newsrc = "../../assets/images/" + itemimg.route + ".jpg";
//alert (newsrc);
this.itemimgs[0].imageUrl = newsrc;