javascript - 使用 ng-repeat 将参数传递给 ng-click 函数
问题描述
请看下面的代码:
<div>
<div class="list-group">
<a class="list-group-item" ng-click="c.selectItem(note.sys_id)"
ng-repeat="note in data.notes">
<h4 class="list-group-item-heading">
{{note.title}}
</h4>
<p class="list-group-item-text">
{{note.sys_id}}
</p>
</a>
</div>
</div>
在输出中,我可以看到 note.sys_id 正在打印。但是,我需要将其传递给顶部的 ng-click 函数。我尝试了下面的代码,但没有结果:
ng-click="c.selectItem(note.sys_id)"
ng-click="c.selectItem({{note.sys_id}})"
解决方案
https://jsfiddle.net/1q8mdb3z/
ng-click="c.selectItem(note.sys_id)"
应该为你工作。确保你的函数是正确的。我假设你的范围是有效果的
$scope.c = {
selectItem = function(id) {
// do something with id
}
}
推荐阅读
- javascript - D3 退出过渡:动画在移除前向左平移
- .htaccess - 同时存在两条规则及其顺序
- java - 如果条件为真,则尝试停止执行方法时无法访问代码
- compiler-construction - 操作系统设计是否使用编译原理知识?
- c# - 如何检测双精度数组中的异常值?
- html - 我的滚动内容很小,为什么?
- c# - 如何解决错误“字典中不存在给定的键。” 使用 MySqlDataAdapter 的数据集时?
- haskell - 根据子类优化超类方法
- ffmpeg - ffmpeg 实时网络摄像头颜色键减法并在桌面上显示提要(减色透明/桌面透视可见))
- java - Instant Apps:如何添加外部库?