Refresh image without changing ng-src

2,453 views
Skip to first unread message

alec...@gmail.com

unread,
Sep 26, 2013, 3:41:23 PM9/26/13
to ang...@googlegroups.com
Hello,

I have a REST service which returns a logo for a given company. The end-point of this service is used in ng-src of an <img> HTML element. I also have an image upload form which allows the user to upload a new logo.

I need the image to refresh after a successful upload. Currently my workaround is to append a unique timestamp to ng-src to force image reload as follows:

$scope.$apply(function () {
  $scope.imageUrl = imageUrl + '?' + new Date().getTime();
});

Is there a cleaner way to accomplish image refresh without modifying ng-src or reloading the page?

Thanks,

Alec

Luke Kende

unread,
Sep 27, 2013, 2:09:33 AM9/27/13
to ang...@googlegroups.com
I would look at using a custom directive instead of ng-src. Then you can control the source yourself and set a variable from parent scope even to trigger an update.  Don't have time to code it out right now, but just giving you some direction to chew on.
Reply all
Reply to author
Forward
0 new messages