I have an AngularJS application where I am using a function called foo(bar) that takes bar as a parameter. The data for bar is retrieved from a web API, and I loop through this data using ng-repeat which works perfectly fine.
<li class="list-group-item" ng-repeat = "tag in subreddit.tags">
<a href="javascript:void(0);" ng-click="subreddit.getData(tag)" target="_blank">{{tag.data.url}}</a>
</li>
The getData function works as expected with the ng-repeat directive. However, I encountered an issue when defining another instance of getData in the same app:
<button class="btn btn-success btn-block" ng-click="subreddit.getData(tag);">Load Feeds...</button>
This time, getData does not work because the parameter 'tag' is undefined, unlike in the case of ng-repeat where it was provided by the data.
To further illustrate my problem, I have created a demo to showcase the issue.
Steps to reproduce:
1. Click on the Reddit links to see the data being populated correctly in the console
2. Click on the red button "Load Feeds" which calls the same function but doesn't work
If anyone can provide insight into how to resolve this issue or point out what mistake I might be making, I would greatly appreciate it.
Demo of the Issue: