Angular ng-repeat ng-click 参数未传递给函数调用,为什么?

Angular ng-repeat ng-click parameter not passed to function call, why?

我有一个简短的细节。 基本上我想要实现的是一个带有点击功能的按钮列表,而该功能没有得到项目 - 它 returns 变量的文字名称。很奇怪。

http://plnkr.co/edit/hFt91zkF8lZiPVvfvS4R?p=preview

<li ng-repeat="comp in listOfItems"><button class="btn btn-default" ng-click='onSearchBtnClick("{{ comp }}")' >{{ comp }}</button></li>

按钮列表显示正确,在 chrome 开发工具中它显示正确的函数调用:

ng-click="onSearchBtnClick("when")"

手动添加的 <li> 按预期工作。其他人得到 {{ comp }} 作为字符串而不是它的值。

你需要像下面那样做你不需要 ng-repeat

里面的 {{ }}
<li ng-repeat="comp in listOfItems"><button class="btn btn-default" ng-click='onSearchBtnClick(comp)' >

ng-click evaluate a expression here is the DOC, so you dont need to put {{ }}

updated Plunker

只需使用onSearchBtnClick(comp)。 属性 存在于范围内,不需要进行插值。通过使用 "",您实际上是在使用字符串文字作为参数,因此按字面意思传入 "{{ comp }}"

你可以做下面的表达式。

<li ng-repeat="comp in listOfItems"><button class="btn btn-default" ng-click="onSearchBtnClick('{{comp}}')" ></li>