Angularjs传递参数值在NG-点击功能 [英] Angularjs passing parameter values in ng-click function
问题描述
我有一个角应用,在那里我有定义为 sumCompletedCredits
自定义过滤器。这里是调用的HTML:
I have an angular app where i have a custom filter defined as sumCompletedCredits
. Here is the html of the call:
{% if node.is_leaf_node %}
<span class="badge badge-success"
ng-bind="mpttdetails | filter:{category.id:{{node.id}}} | sumCompletedCredits">
</span>
<div class="row">
<button class="btn btn-default btn-sm pull-right"
ng-click="open({{node.id}}, {{node.min_credit}})">Add Course <span class="glyphicon glyphicon-plus"></span>
</button>
</div>
{%endif%}
下面是自定义过滤器定义:
Here is the custom filter definition:
app.filter('sumCompletedCredits', function () {
return function (mpttdetails) {
if(typeof mpttdetails === 'undefined'){
return;
}
else {
var sum = 0;
mpttdetails.forEach(function (detail) {
sum += detail.student_academic_credit.credit;
});
return sum;
}
};
});
下面是我想要实现:我想通过按钮的纳克单击第三个参数()
函数,其中的参数是从价值上述跨度就像如下:
Here is what i want to achieve: I would like to pass a 3rd parameter in the button's ng-click()
function where the parameter would be the value from the above span like the follows:
ng-click="open({{node.id}}, {{node.min_credit}}, *{{{this content will be the value in the badge class from the custom filter}}}*)"
所以基本上我试图发送只会按钮之前显示在跨度徽章的价值和发送该值作为第三parameter.How做我送第三个细节?
So basically i am trying to send the value that will be displayed in the span badge just before the button and send that value as the third parameter.How do i send the third detail?
推荐答案
您可以过滤的结果分配给一个作用域属性和参考,在你的函数属性:
You can assign the result of the filtering to a scope property and reference that property in your function:
<span ...
ng-bind="summed=(mpttdetails | filter:{category.id:{{node.id}}} |
sumCompletedCredits)">
</span>
...
<button ...
ng-click="open({{node.id}}, {{node.min_credit}}, summed)">
...
</button>
这篇关于Angularjs传递参数值在NG-点击功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!