Reputation: 19195
In HTML
I want to make a clickable image which then calls a TypeScript
function using an Angular
directive. I'm using Angular
version 2.4.10
.
I tried various snippets but none worked and I always get the warning Attribute ng-click is not allowed here
:
<a ng-click="myTypeScriptFunction()"> <img src="url-to-my-image"/></a>
With onClick()
and an alert()
dialog it works fine:
<a onClick="alert('It worked');"> <img src="url-to-my-image"/></a>
How can it be done with Angular
?
Upvotes: 4
Views: 26653
Reputation: 657308
In Angular 2/4 for event binding you use
<a (click)="myTypeScriptFunction()"> ... </a>
This is documented here: https://angular.io/docs
Upvotes: 6
Reputation: 41571
You should be using click
event binding
<button (click)="yourMethod()"> <img src="url-to-my-image"/></button>
Upvotes: 2
Reputation: 282
change for this code :
<a (click)="myTypeScriptFunction()"> <img src="url-to-my-image"/></a>
Upvotes: 4