Reputation: 1797
I have this elements here:
<a href="#item1" ng-click="myfunc('arg1', 'arg2')">Item1</a>
<a href="#item2" ng-click="myfunc('arg1', 'arg2')">Item2</a>
"myfunc" expects 2 incoming arguments. Now, I also need something else, which is the content of the href-attribute.
I could do one of the following
1 - Add a new argument to the function
2 - Add the event argument to read the content of href-attribute
However, in this application there seems to be many other places where the function "myfunc" is called. This means I would need to modify them to reflect the new argument list.
So what I wonder is if there is someway in the controller to know what attribute the calling element's href contains. Is that even possible?
Upvotes: 1
Views: 168
Reputation: 1392
The problem here is you put a service method in a controller. Move the myfunc function to a service and add the href param to it. Then from your controller and other places call this service method.
In you controller you can then get the href via :get original element from ng-click
In other calls of myfunc you will have to get the href from a different source.
Upvotes: 1