Always_a_learner
Always_a_learner

Reputation: 5055

how to use onload event in angular 2 with dynamically inserted image source

I want to set certain flags when image is downloaded. I tried using onload event on image tag and call function. With what I implemented below I am getting error:

Uncaught ReferenceError: imageLoaded is not defined at HTMLImageElement.onload

component.html:

 <img onload='imageLoaded()' class='doc-img' [src]='imageUrl'>

component.ts:

ngOnInit()
{
  this.getDocumentImage()
}

getDocumentImage()
{
     this.imageUrl= 
this.domSanitizerService.bypassSecurityTrustResourceUrl(`${API.document}/{documentId}`);
}

imageLoaded(){
    alert("image loaded");
}

Need some article reference or help in debugging this.

Thanks!

Upvotes: 0

Views: 2246

Answers (1)

Azizul Hoq
Azizul Hoq

Reputation: 629

<img (load)='imageLoaded()' class='doc-img' [src]='imageUrl'>

Upvotes: 3

Related Questions