0

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.

3
  • IT SHOULD BE: ng-repeat="item in Playlist.item" ng-click="getSingleItem(item)" Commented Apr 2, 2017 at 17:47
  • I know, it's just a copy pas error on stackoverflow. i find out that it work with my own directive and the ng-click stop functionning, but it work if i just add a $timeout in my directive. Commented Apr 3, 2017 at 20:22
  • @Gino you should post your answer, if you have one. Commented Apr 3, 2017 at 20:45

3 Answers 3

1

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)"
Sign up to request clarification or add additional context in comments.

Comments

0

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)"

Comments

0

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!

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.