Aless Hosry
Aless Hosry

Reputation: 1189

Getting values of specific tr in table repeated through angular JS using filters

I am calling an API which will return a JSON object. Based on some conditions I am getting values from this JSON object and displaying them in a table which can be repeated using angular JS. Now I need to get data of each table but I don't know how as some data is filtered.

Below is the table:

    <table class="table">    
            <thead>
            <tr>
                <th>Relation
                </th>
                <th>Date Of Birth
                </th>
                <th >In Hospital
                </th>
                <th >AMB & PM 
                </th>            
                <th > Total
                </th>                 
            </tr>   
        </thead>
           
        <tr ng-repeat="member in CalculatorResponse">        
            <td>
               {{member.Relation}}                                          
            </td>
            <td>{{member.dateOfBirth}}
            </td>
            <td> 
                <span ng-repeat=" InHosp in member.InHospital | filter:{strClassName: class.className}">
                  {{InHosp.intClassValue}}
                </span>
               
            </td>
            <td >
                <span ng-repeat=" OutHosp in member.OutHospital | filter:{OptionType: Option_Select.type}">
                     <span ng-model="AMBPMVal" ng-repeat=" Benefits in OutHosp.Benefits | filter:{intExcess: CoBenefitsSelect.type}">
                          {{Benefits.intAMBPM}}
                    </span>
                </span>                                                                                  
            </td>       
           <td> Total value (unable to calculate it) {{InHosp.intClassValue}} + {{Benefits.intAMBPM}} 
        </td>     
    </tr>
</table>

<input type="button" value="Generate"  ng-click="Generate()"/> 

So the main problem is that I am trying to get all values of the table when generate button is clicked, but I cannot get the filtered values;

  1. I did this but it is not working:

    <span ng-repeat=" OutHosp in (filteredHosp = (member.OutHospital | filter:{OptionType: Option_Select.type}))">
        <span ng-repeat=" Benefits in (filteredBenefits = (OutHosp.Benefits | filter:{intExcess: CoBenefitsSelect.type}))"> {{Benefits.intAMBPM}}  </span> 
        <%--{{filteredBenefits[0].intAMBPM}}--%> </span> <%--{{filteredHosp[0].Benefits}}--%>
    

--> filtered benefits and filteredHosp can be only accessed in the commented region, if you put them outside the 2 spans you will get nothing.

  1. I am also trying also to calculate the total of In Hospital and AMB&M but I cannot as I don't know how to get their values after filter.

Any suggestion?

Upvotes: 0

Views: 71

Answers (1)

NTP
NTP

Reputation: 4448

They are not available, not because of filter but because they are outside the scope of ng-repeat. You can either do your calculations inside ng-repeat or iterate through your list and do calculations in your controller.

Upvotes: 2

Related Questions