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?
In Angular 2/4 for event binding you use
<a (click)="myTypeScriptFunction()"> ... </a>
This is documented here: https://angular.io/docs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With