Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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}}}*)"

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?

share|improve this question
    
Have you tried just putting the same code / filter in the function? –  JakeSidSmith May 22 at 23:11
    
Yeah I tried it but the ng-click definition was being violated and it threw me an error –  crozzfire May 23 at 0:44
    
Possible for you to import filters in your controller / directive and then call it inside your open function? $filter('filtername')(arg); –  JakeSidSmith May 23 at 7:39

1 Answer 1

up vote 2 down vote accepted

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>
share|improve this answer
    
can we assign them like an array like this since my buttons and spans are in a loop and the values will be updated after every run? ng-bind="summed[{{node.id}}] = (mpttdeta...)" –  crozzfire May 23 at 15:10
1  
Sure, but in that case you need to initialize summed in your controller. E.g. have a line like this: $scope.summed = []; –  ExpertSystem May 23 at 15:18
    
hi can you help me here? stackoverflow.com/questions/24247130/… –  crozzfire Jun 16 at 15:25

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.