4

The full error is:

Error: [$parse:syntax] Syntax Error: Token ',' not a primary expression

The piece of code causing the error is:

<div ng-repeat="item in items">

    <input type="submit" ng-click="delete({{item.itemId}},$index)" value="delete">

</div>

The function actually works for previous items but breaks when I try a new item to my item array. The problem child appears to be the comma, but I do not know what to do.

2
  • please post your model items Commented Oct 24, 2013 at 17:04
  • Thanks I found that the error had to do with a function on my factory. Commented Oct 24, 2013 at 18:53

1 Answer 1

10

You don't need to wrap item.itemId in {{}}. Just do:

ng-click="delete(item.itemId, $index)"

You only need to wrap in braces when using Angular's templating system - the braces tell Angular to replace the value. In this case, the value of ng-click is an expression that is evaluated (within the scope of your controller) when a click event occurs.

Demo Fiddle

Sign up to request clarification or add additional context in comments.

1 Comment

The error was actually completely different, but +1 for some extra information. Actually, I recently realized that neither of these things need to be passed in, as you can pull both the object of interest and the index from the this variable.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.