Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to Parse JSON response into ng-repeat correctly in Angularjs
    text
    copied!<p>I want to be able to use <code>ng-repeat</code> in order to parse my response on the front end. I am having trouble parsing responses that have multiple items versus a single item using <code>ng-repeat</code> list.</p> <p>I am able to parse; but I have to create 2 different list with separate <code>ng-repeat</code> configuration on the front end and add some ugly logic to not display if length of array is greater than one. </p> <p>My goal is to have only one <code>ng-repeat</code> element in my partial and it handles both responses or a better approach to handle this requirement. </p> <p>Detailed Explanation and jsfiddle below.<br> I want to use this ng-repeat setup for both JSON responses.</p> <pre><code> &lt;ul ng:repeat="report in reportConfigured.Reports"&gt; &lt;li ng:repeat="reportItem in report"&gt;{{reportItem.ReportName.$}}&lt;/li&gt; &lt;/ul&gt; </code></pre> <p>Below is the response I get from my webservice when there are multiple reports.</p> <pre><code>{ "Reports": { "@xmlns": { "$": "http:\/\/ws.wso2.org\/dataservice" }, "Report": [{ "ReportID": { "$": "20" }, "ReportName": { "@xmlns": { "$": "null" }, "$": "Examination Results" }, "VisibleToPartner": { "$": "false" }, "ReportType": { "@xmlns": { "$": "null" }, "$": "Examination Report" }, "TemplateID": { "$": "9" } }, { "ReportID": { "$": "163" }, "ReportName": { "@xmlns": { "$": "null" }, "$": "Scheduled Candidates with Test Center" }, "VisibleToPartner": { "$": "false" }, "ReportType": { "@xmlns": { "$": "null" }, "$": "Examination Report" }, "TemplateID": { "$": "220" } }, { "ReportID": { "$": "212" }, "ReportName": { "@xmlns": { "$": "null" }, "$": "Survey Report by Test" }, "VisibleToPartner": { "$": "false" }, "ReportType": { "@xmlns": { "$": "null" }, "$": "Examination Report" }, "TemplateID": { "$": "269" } }] } }; </code></pre> <p>I get this response from my service when there is only one report</p> <pre><code> { "Reports": { "@xmlns": { "$": "http:\/\/ws.wso2.org\/dataservice" }, "Report": { "ReportID": { "$": "212" }, "ReportName": { "@xmlns": { "$": "null" }, "$": "Survey Report by Test" }, "VisibleToPartner": { "$": "true" }, "ReportType": { "@xmlns": { "$": "null" }, "$": "Examination Report" }, "TemplateID": { "$": "269" } } } } </code></pre> <p>I want to be able to parse both responses with the same <code>ng-repeat</code>. I have attached a jsfiddle for more details.</p> <p><a href="http://jsfiddle.net/cejohnson/mdec9/1/" rel="nofollow">http://jsfiddle.net/cejohnson/mdec9/1/</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload