Angular function with two parameters having Error: [$parse:syntax]

醉酒当歌 提交于 2019-12-12 11:35:58

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/19572056/angular-function-with-two-parameters-having-error-parsesyntax

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!