I want to call a function in type script component from <a>
tag using href
like this:
<a href="fun()" ></a>
Is it possible in some way? Note that I need only this way. Using a click
event does not help in my case.
I tried already this:
<a href="javascript:fun()">
But it does not work.
thanks!
In JavaScript, you can call a function or snippet of JavaScript code through the HREF tag of a link. This can be useful because it means that the given JavaScript code is going to automatically run for someone clicking on the link. HREF refers to the “HREF” attribute within an A LINK tag (hyperlink in HTML).
You need to arrange things so the function is in scope and then you can just call it with {{getConfigurations(param)}} but people can't give you proper help without more info.
AngularJS ng-href DirectiveThe ng-href directive should be used instead of href if you have AngularJS code inside the href value. The ng-href directive makes sure the link is not broken even if the user clicks the link before AngularJS has evaluated the code.
you cannot call function in href use role
attribute and make <a>
as button and call the function with (click)
<a role="button" (click)="func()"></a>
I know this is an old question. This worked for me on Angular 6 -
<a href="javascript:void(0);" (click)="getSampleCSV()">CSV Template</a>
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