0

This is essentially my HTML. It is part of a responsive design so I cannot rely on fixed widths/heights:

<img ng-src="{{imageSrc}}" />

The value of $scope.imageSrc is changed inside my controller and the view is updating properly.

But: At the point of time the image has finished rendering I need to get its clientWidth and clientHeight properties.

So how can I detect programmatically that

  1. the image has finished loading and
  2. the view has been fully updated with the rendered image

without using weird timeouts?

3
  • 1
    I think $timeout(, 0) in onload should do the trick for 2. Commented Sep 17, 2015 at 13:51
  • It works but it seems weird to use this type of "timeout hack" Commented Sep 17, 2015 at 14:27
  • I am not condering this a hack. Javascript is one thread, so using timeout with 0 is absolutely ok, behavior of such code is quite stable. Well, at least I think so. Commented Sep 17, 2015 at 18:08

1 Answer 1

3

Two other questions will help you here. This SO post will detect loading via the load event.
And this post will detect rendering via requestAnimationFrame.

Sign up to request clarification or add additional context in comments.

2 Comments

I will check this out
Yes that does the trick ... I can even get the rendered image's width/height within the first requestAnimationFrame callback

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.