Per answer here Detect when image has loaded in img tag hook into load event
import { Component, Input, ElementRef, ViewChild } from '@angular/core';
@Component({
selector: 'hello',
template: `
<img #hdImage
src="https://upload.wikimedia.org/wikipedia/commons/f/ff/Pizigani_1367_Chart_10MB.jpg"
(load)="dosomething(hdImage.width)">
`,
styles: [``]
})
export class HelloComponent {
@ViewChild('hdImage', { static: false }) HdImage: ElementRef;
img: HTMLImageElement;
dosomething(width: number) {
console.log('[dosomething] width', width);
}
}
@AlexandrMihalciuc answer is better as it is better to pass the width directly so I've stolen it to improve this now accepted answer.