Basic array looping in AngularJS

Basic array looping in AngularJS



Can someone explain to me why this doesn't loop?



If I pre napIncident it gives null.



My code


<tr ng-repeat="napIncident in vm.NapIncidents">
<pre>vm.NapIncidents </pre>
<td>
napIncident.Incident
</td>



Pre output


[

"NapIncident":
"Incident": "Zahlunsverbindungen ändern",
"IncidentID": "0002724285",
"NapID": "4214",
"NapStatus": "erfasst",
"Username": "silvat",
"NumberOfApprovers": "2",
"RecordDate": "12-12-2018",
"CheckerInformationList": [

"CheckerInformation":
"Checker": "silvat",
"Date": "21-09-2018",
"TimeOfDay": "12:12:36",
"CheckerInfo": "Something",
"CheckerInfoText": "Something else"


],
"Alterations": [

"Alteration":
"Field": "IBAN",
"OldValue": "DE12345",
"NewValue": "DE54321"


]


]






your key is NapIncident, but you are using Incident. Change this line napIncident.Incident to napIncident.NapIncident

– Aleksey Solovey
Sep 10 '18 at 9:14


NapIncident


Incident


napIncident.Incident


napIncident.NapIncident






Any progress ...?

– davidkonrad
Sep 19 '18 at 10:03




2 Answers
2



you have to access to your item . In your case is napIncident. Check your html part you will find ng repeat "NapIncident in vm.NapIncidents" .
To access to the details NapIncident.NapIncident.Incident



When using ng-repeat you map each item to a temporary variable, and when you have an array of named literals i.e array of NapIncident: ... you must refer to NapIncident as a property :


ng-repeat


NapIncident: ...


NapIncident


<tr ng-repeat="item in vm.NapIncidents">
<td>
item.NapIncident.Incident
</td>
<td>
item.NapIncident.IncidentID
</td>
</tr>



and so on.



Thanks for contributing an answer to Stack Overflow!



But avoid



To learn more, see our tips on writing great answers.



Required, but never shown



Required, but never shown




By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.