Clickable image with Angular 2.x

Viewed 24140

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?

3 Answers
Related