0

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?

1 Answer 1

2

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.

6
  • You mean by this to calculate the total from the controller and display it like {{member.dateOfBirth}} so -> {{member.Total}} ? and what if total depends on shown data? In other words if AMB & PM was hidden total should be only In Hospital. Is that possible ?
    – Mlle 116
    Dec 4, 2017 at 14:22
  • And one more question: if I add {{member.Total}} now data on generate click can be accessed by looping through the json array of CalculatorResponse right?
    – Mlle 116
    Dec 4, 2017 at 14:24
  • you should also filter your data in controller when doing your calculations
    – NTP
    Dec 4, 2017 at 14:24
  • since I do not know content of your generate function, I cannot comment about that but if you add your generate function to your question I am sure we can figure something out.
    – NTP
    Dec 4, 2017 at 14:29
  • I will revert back once I finish it, but for now thank you for your help.
    – Mlle 116
    Dec 4, 2017 at 14:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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