Angular get image size


I have a modal with a large oversize image. I’m trying to read the image size so I can set a scroll view to horizontal or vertical depending on the image size.

When I try this:

this.dragImageItem = <Image>this.dragImage.nativeElement;
        this.imageDimension = this.dragImageItem.getActualSize();
        console.log("Size: ", this.imageDimension);

It logs the size as

"width": 0,
"height": 0

Is there another method I should use?


If you try to get dimension before any view is rendered, it will be 0 only. Try using a timeout, give enough time for it to be rendered on screen.


Thanks, that was the trick.