最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Angular function with two parameters having Error: [$parse:syntax] - Stack Overflow

programmeradmin0浏览0评论

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 ma, but I do not know what to do.

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 ma, but I do not know what to do.

Share Improve this question asked Oct 24, 2013 at 16:58 ConquerorConqueror 4,4738 gold badges36 silver badges42 bronze badges 2
  • please post your model items – Maxim Shoustin Commented Oct 24, 2013 at 17:04
  • Thanks I found that the error had to do with a function on my factory. – Conqueror Commented Oct 24, 2013 at 18:53
Add a ment  | 

1 Answer 1

Reset to default 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

发布评论

评论列表(0)

  1. 暂无评论