0

I am trying to use interpolation to pass value of src attribute of img HTML element. However, this influences how the element is rendered, the element is rendered as a literal.

<div *ngFor="let tour of tours" class="col-md-4 tour-tile">
  <div class="tour-tile-inner">
    <div class="top-bar">{{ tour.name }}</div>
    <img class="myimage img-responsive thumbnail" src="{{"/images/tours/kutna-hora/tile.jpg"}}" alt="">
  </div>
</div>

enter image description here

I tried also src={{...}} instead of src="{{...}}" with the same result. I do not know why the literal is rendered.

Martin Staufcik
  • 8,295
  • 4
  • 44
  • 63
  • 1
    Not sure why you want to use interpolation in that case, but using inner single quotes should work: `src="{{'/images/tours/kutna-hora/tile.jpg'}}"`. The simple syntax would be ``src="/images/tours/kutna-hora/tile.jpg"``, without interpolation. – ConnorsFan Sep 26 '20 at 16:43
  • @ConnorsFan Thank you, with single quote inside the curly brackets it is working. I tried to simplify the code, that is why there is only a string in the expression. – Martin Staufcik Sep 26 '20 at 16:47
  • Does this answer your question? [Angular 2 change image src attribute](https://stackoverflow.com/questions/38334010/angular-2-change-image-src-attribute) – mbojko Sep 26 '20 at 18:35

0 Answers0