Adding parameter to ng-click function inside ng-repeat doesn't seem to work


I have a simple loop with ng-repeat like this:

<li ng-repeat='task in tasks'>
  <p> {{}}
  <button ng-click="removeTask({{}})">remove</button>

There is a function in the controller $scope.removeTask(taskID).

As far as I know Angular will first render the view and replace interpolated {{}} with a number, and then, on click event, will evaluate ng-click string.

In this case ng-click gets totally what is expected, ie: ng-click="removeTask(5)". However… it’s not doing anything.

Of course I can write a code to get from the $tasks array or even the DOM, but this does not seem like the Angular way.

So, how can one add dynamic content to ng-click directive inside a ng-repeat loop?


Instead of

<button ng-click="removeTask({{}})">remove</button>

do this:

<button ng-click="removeTask(">remove</button>

Please see this fiddle:

Answered By – Chubby Boy

Answer Checked By – Mildred Charles (AngularFixing Admin)

Leave a Reply

Your email address will not be published.