Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 9 onclick function not defined [duplicate]

dashboard.component.ts

myFunction(){
      console.log("test");
  }

dashboard.component.html

<img [src]="team.logo" onclick="myFunction()" alt="img">

Whenever the image is clicked, error appears in console saying "Reference error: myFunction is not defined". I have tried using ng-click aswell but no luck.

like image 425
Shubham Avatar asked Jul 13 '26 04:07

Shubham


1 Answers

You need to do the following,

In your dashboard.component.html file,

<img [src]="team.logo" (click)="myFunction()">
like image 153
thisdotutkarsh Avatar answered Jul 15 '26 16:07

thisdotutkarsh