Kenny G
Kenny G

Reputation: 33

Get clicked item from ng-repeat

I'm currently working on a project where i'm using angular.

I got an array and i put that array in a list item and show the elements from that array

<ul>
    <li ng-repeat="Answers in Multiples">
         <button ng-click="addAnswer()">{{Answers}}</button>
    </li>
</ul>

Now i want when i click on one of the buttons that it shows the value of that object.

$scope.addAnswer(){
   console.log('Item i clicked on');
}

Upvotes: 1

Views: 673

Answers (1)

tymeJV
tymeJV

Reputation: 104775

Just pass in the variable being iterated over:

<button ng-click="addAnswer(Answers)">{{Answers}}</button>

And use it:

$scope.addAnswer(answers){
    console.log('Item i clicked on', answers);
}

Upvotes: 3

Related Questions