Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Appending string to img src in angular 4

Tags:

angular

How can we append string to src content.

<img [src] = "data.imagePath"+".jpg">   

I know its wrong.

But in angular version 1 we could achieve this

<img ng-src="{{data.imagePath}}.jpg">

My json is providing only the name of picture without extension. So how could I achieve this in angular 4.

like image 904
Anuj K.C. Avatar asked Oct 17 '17 13:10

Anuj K.C.


2 Answers

Like this :

<img src = "{{data.imagePath}}.jpg">

or

<img [src] = "data.imagePath+'.jpg'">
like image 172
Vivek Doshi Avatar answered Sep 20 '22 09:09

Vivek Doshi


This

<img [src]="data.imagePath + '.jpg'" />

should work.

like image 23
Christian Benseler Avatar answered Sep 21 '22 09:09

Christian Benseler