簡體   English   中英

Angular2-HTML中的動態變量

[英]Angular2 - dynamic variable in html

我有一個看起來像這樣的清單:

<ul *ngFor="#item of items">
<li><img src="http://something.com/[this needs to be item.id]/picture"></li>
</ul>

我需要圖片網址是商品ID的網址。 我查看了angular2的src文檔( https://angular.io/docs/ts/latest/guide/template-syntax.html ),並嘗試了以下操作:

<img [src]="http://something.com/{{item.id}}/picture">

但它沒有用。 如何根據需要在網址中包含的商品ID顯示圖片。

對字符串文字使用屬性綁定:

<img [src]="'http://something.com/' + item.id + '/picture'">

或與{{}}綁定的字符串插值屬性:

<img src="http://something.com/{{item.id}}/picture">

請注意, [src]="http://something.com/{{item.id}}/picture">無效,因為與[]屬性綁定使用語法[property]="template_expression" ,而template_expression可以不包含{{}}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM