Reputation: 878
I am trying to find out the logo dimensions, since different clients can upload different logos. The HTML is like this:
<img [src]="layoutResponseModel?.clientLogo" alt="">
How can I get width and height of this image in Angular 5? Found a few JS examples but couldn't make it work
Upvotes: 5
Views: 8164
Reputation:
Give your image a template variable a load hook :
<img [src]="layoutResponseModel?.clientLogo" alt="" #logo (load)="onLoad()">
Reference it in your component :
@ViewChild('logo') logo: ElementRef;
Write your load hook :
onLoad() {
console.log((this.logo.nativeElement as HTMLImageElement).width);
}
This will give you the width of the displayed image.
Upvotes: 12