Reputation: 1854
I add a ng-click inside a ng-repeat, i want to get the single item in the loop, it work well but only once.
ng-repeat="item in Playlist.item" ng-click="getSingleItem(item)"
in my controller
$scope.getSingleItem = function (item) { console.log(item); }
If i click i get the item object in my console log, this click is a href and send me to the next page with ng-route. But if i go back and click the same link or another link, it won't work.
it fire only once.
UPDATE! i just find out that with my own href directive and the ng-click it work only once, but if i just add a $timeout in my own directive it will work.
Upvotes: 0
Views: 914
Reputation: 463
I am not sure what you are doing after the ng-repeat since your post doesn't have any other code, but I am guessing it is because you are not listing out the items you have in the ng-repeat.
I've done something like this which has worked:
<div>
<table>
<thead>
<tr>
<td>Item</td>
</tr>
</thead>
<tbody ng-repeat="item in Playlist.item" ng-click="getSignleItem(item)">
<tr>
<td>{{item}}</td>
</tr>
</tbody>
</table>
</div>
You should now be able to do click on the item listed in the table which then executes the ng-click passing the clicked item.
Cheers!
Upvotes: 0
Reputation: 222582
Not sure if you have posted the correct code, your ng-click should be placed outside ng-repeat,
ng-repeat="item in Playlist.item" ng-click="getSingleItem(item)"
Upvotes: 1
Reputation: 1210
You have an error in your HTML code. You're missing a comma in that line. This should be:
ng-repeat="item in Playlist.item" ng-click="getSingleItem(item)"
Upvotes: 0