如何在图像的 src 中使用 {{ }} ? 我在 [src] 附近遇到此代码错误
<ion-list>
<ion-item *ngFor="let item of results| async">
<ion-thumbnail slot="start">
<ion-img [src]={{ item.qrlink }}></ion-img>
</ion-thumbnail>
<ion-label>{{ item.Title }}</ion-label>
</ion-item>
</ion-list>
在 page.ts 中我有以下代码:
submit_newcheck()
{
this.results = this.encryptionService.newcheck(this.checkid,this.cost,this.toname,this.tocode,this.passcode,this.date );
}
它连接到这样的服务:
export class EncryptionService {
constructor(private http: HttpClient) { }
newcheck(checkid: string ,cost: string,toname: string,tocode: string,passcode: string,date: string): Observable<any> {
return this.http.get(`https://api.test.com/encrypte.php?checkid=${encodeURI(checkid)}&&cost=${encodeURI(cost)}&&toname=${encodeURI(toname)}&&tocode=${encodeURI(tocode)}&&passcode=${encodeURI(passcode)}&&date=${encodeURI(date)}`).pipe(
map(results => results['Data'])
);
}
}
最佳答案
它应该是[src]="item.qrlink"
或src={{ item.qrlink }}
。它们不应该混合在一起。
说明
在[src]="item.qrlink"
的情况下,变量item.qrlink
的值绑定(bind)到[src]
使用属性绑定(bind)的属性。阅读有关模板表达式的更多信息 here .
如果是 src={{ item.qrlink }}
,则值 item.qrlink
会被插值并分配给属性 src
。了解有关插值的更多信息 here .
关于javascript - 如何在图像src ionic中使用变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60950475/