I have a component based around <canvas [attr.width]='gameWidth' [attr.height]='gameHeight'></canvas>
On a given event I want to update the properties bound to width
and height
then re-draw some content into the newly re-sized canvas.
The issue arises when I try to update the bound properties and then immediately trigger a re-draw. The canvas re-sizes but the drawing does not take place.
I made a plunk that shows the problem. Clicking the canvas changes its dimensions just fine but the subsequent call to doRender()
has no effect.
I'm assuming there is some delay while the element updates, during which drawing is not possible. In this example I can get round the issue by using Observable.timer()
to call doRender()
on a delay but this feels dirty and I'd like to know what the underlying problem is here and if there is nicer way to ensure that the canvas context is ready before I start drawing.
Thanks all