1

I was trying to update the image being displayed after an image file with same name overwrote the previous file and came across this link:Reload/refresh an element(image) in jQuery

I had a scope element "imgUrl" which I was passing in the data-ng-src as:

<img data-ng-src="{{imageUrl + '?' + GetTimeStamp()}}">

This thing worked but I also tried this:

<img data-ng-src="{{imageUrl}} + '?' + {{GetTimeStamp()}}">

And this didn't work. Whats the difference between these two expressions?

Community
  • 1
  • 1
Vishal Chugh
  • 337
  • 1
  • 6
  • 12

1 Answers1

3

The opening brackets {{ indicate that an angular expression begins, and the closing brackets }} indicate that it ends. Everything outside of the brackets is considered to be a plain text attribute. Therefore, the + becomes just a text symbol between the two expressions, rather than acting as the string concatenation operator.

Kazimieras
  • 607
  • 4
  • 14
  • 1
    "Everything, that follows the closing brackets" - to be precise, it's "everything outside of `{{ }}`" – Sergio Tulentsev Jun 10 '16 at 09:56
  • @SergioTulentsev You are right, that was rather ambiguous, since anything can follow the brackets. Edited the answer. Thank you! – Kazimieras Jun 10 '16 at 09:59
  • 1
    @Kazimieras And if I hadn't used + and just this: {{imageUrl}}?{{GetTimeStamp()}}. Had it been fine? – Vishal Chugh Jun 10 '16 at 10:03
  • @VishalChugh This is also fine. In this case you are just evaluating two simpler expressions instead of a more complex one. – Kazimieras Jun 10 '16 at 10:10
  • @VishalChugh if you find that your question has been answered, it would be great if you could mark it as accepted :) – Kazimieras Jun 16 '16 at 13:34