2

I'm trying to create image element dynamically and undertake other work after the element is loaded like below:

const img = new Image();
img.src = imagePath;

fromEvent(img, 'onload').subscribe(() => // do something);

But apparently, fromEvent operator never emits with onload event.

I saw they have discussed it in How to load images async with RxJs and perform a method when all loaded but I'd like to know if there's any other workaround to achieve this without creating an observable myself like using fromEvent.

Any insight would be appreciated!

DongBin Kim
  • 1,799
  • 5
  • 23
  • 43

1 Answers1

4
fromEvent(img, 'load').subscribe(() => // do something);
René Winkler
  • 6,508
  • 7
  • 42
  • 69