[英]AngularJs ngClick Cache Update Issue
I am attempting to pass a value to JavaScript function when ng-click
call. 我尝试在ng-click
调用时将值传递给JavaScript函数。 But its passing wrong value. 但是它传递了错误的价值。
ng-click="removeObj(det, '{{$index+1}}')
here index
is 0 so when i do inspect element in chrome its shows ng-click="removeObj(det, '1')
ng-click="removeObj(det, '{{$index+1}}')
这里的index
为0,因此当我检查chrome中的元素时,显示ng-click="removeObj(det, '1')
In JavaScript function: self.removeObj = function(formObject, id)
-> here id
is coming as 2 instead of 1. 在JavaScript函数中: self.removeObj = function(formObject, id)
->这里的id
是2而不是1。
Sample.html Sample.html
<tbody>
<tr ng-repeat="det in sellingTable">
<td data-title="S.No.">{{$index+1}}</td>
<td data-title="Product">{{det.sellProduct}}</td>
<td data-title="Plan">{{det.sellPlan}}</td>
<td data-title="Amt">{{det.sellAmt}}</td>
<td data-title="Action">
<a href="javascript:void(0)" ng-click="removeObj(det, '{{$index+1}}')">
Remove
</a>
</td>
</tr>
<tr ng-if="sellingTable =='' || sellingTable ==null">
<td colspan="5">No records found</td>
</tr>
</tbody>
Please find below attached chrome inspect element file of my code 请在下面找到我的代码的chrome检查元素文件
Directly pass index 直接通过索引
<a ng-click="removeObj(det, $index+1)"
instead of interpolating 而不是插值
<a ng-click="removeObj(det, '{{$index+1}}')"
You can try it out sans the braces. 如果没有括号,您可以尝试一下。 Here it goes : 它在这里:
<tbody>
<tr ng-repeat="det in sellingTable">
<td data-title="S.No.">{{$index+1}}</td>
<td data-title="Product">{{det.sellProduct}}</td>
<td data-title="Plan">{{det.sellPlan}}</td>
<td data-title="Amt">{{det.sellAmt}}</td>
<td data-title="Action">
<a href="javascript:void(0)" ng-click="removeObj(det, $index+1)">
Remove
</a>
</td>
</tr>
<tr ng-if="sellingTable =='' || sellingTable ==null">
<td colspan="5">No records found</td>
</tr>
</tbody>
Hope it works ! 希望它有效!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.