AngularJs ng-click event only triggered with literal arguments

拜拜、爱过 提交于 2019-12-04 19:34:52

问题


When I call within a ng-repeat group

<span ng-click="remove({{user.id}})">Delete</span>

the remove function is not called

but when I replace the expression by a literal argument it gets called (works properly):

<span ng-click="remove(123)">Delete</span>

The '{{user.id}}' expression is evaluated properly and has only integer values.

Anybody an idea what is going on? Same happens with anchor tags (with href="").


回答1:


ng-click="remove(user.id)" should work, ng-click evaluate it content so you don't need interpolation




回答2:


You shouldn't use curly braces in the ng-click expressions. Try this instead:

<span ng-click="remove(user.id)">Delete</span>

And be sure to check the AngularJS expressions documentation: http://docs.angularjs.org/guide/expression



来源:https://stackoverflow.com/questions/12876059/angularjs-ng-click-event-only-triggered-with-literal-arguments

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