Error in while looping in *ngFor in angular
I have the JSON of single object coming as:
I achieved this data by calling the API in component.ts
file which is as follows
/* for auditgorup selecitonm */
this.http.get('http://localhost:8080/api/selections/getAllAuditGroupSelections')
.subscribe((datas: any) => {
this.auditSelection = datas;
console.log(this.auditSelection);
// You'll have to wait that changeDetection occurs and projects data into
// the HTML template, you can ask Angular to that for you ;-)
this.chRef1.detectChanges();
// Now you can use jQuery DataTables :
const tables: any = $('#nepal');
this.dataTable = tables.DataTable();
});
The view is as follows
<table id="nepal" class="table table-bodered">
<thead>
<tr>
<th>Selection No</th>
<th>SelectionDate</th>
<th>SelectedBy</th>
<th>PanEximNumber</th>
<th>Name</th>
<th>Address</th>
<th>PhoneNumber</th>
<th>SelectionType</th>
<th>Group Desc</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let nas of auditSelection">
<td>{{nas.selectionId}}</td>
<td>{{nas.selectionDate}}</td>
<td>{{nas.selectedBy}}</td>
<td>{{nas.panEximNumber}}</td>
<td>{{nas.name}}</td>
<td>{{nas.address}}</td>
<td>{{nas.phoneNumber}}</td>
<td>{{nas.selectionType}}</td>
<td>{{nas.assignmentAudit.auditorGroup.groupDesc}}</td>
</tr>
</tbody>
</table>
At this last line of <td>{{nas.assignmentAudit.auditorGroup.groupDesc}}</td>
I cannot get the required value.
The output display should be "g1".
javascript angular angular6
add a comment |
I have the JSON of single object coming as:
I achieved this data by calling the API in component.ts
file which is as follows
/* for auditgorup selecitonm */
this.http.get('http://localhost:8080/api/selections/getAllAuditGroupSelections')
.subscribe((datas: any) => {
this.auditSelection = datas;
console.log(this.auditSelection);
// You'll have to wait that changeDetection occurs and projects data into
// the HTML template, you can ask Angular to that for you ;-)
this.chRef1.detectChanges();
// Now you can use jQuery DataTables :
const tables: any = $('#nepal');
this.dataTable = tables.DataTable();
});
The view is as follows
<table id="nepal" class="table table-bodered">
<thead>
<tr>
<th>Selection No</th>
<th>SelectionDate</th>
<th>SelectedBy</th>
<th>PanEximNumber</th>
<th>Name</th>
<th>Address</th>
<th>PhoneNumber</th>
<th>SelectionType</th>
<th>Group Desc</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let nas of auditSelection">
<td>{{nas.selectionId}}</td>
<td>{{nas.selectionDate}}</td>
<td>{{nas.selectedBy}}</td>
<td>{{nas.panEximNumber}}</td>
<td>{{nas.name}}</td>
<td>{{nas.address}}</td>
<td>{{nas.phoneNumber}}</td>
<td>{{nas.selectionType}}</td>
<td>{{nas.assignmentAudit.auditorGroup.groupDesc}}</td>
</tr>
</tbody>
</table>
At this last line of <td>{{nas.assignmentAudit.auditorGroup.groupDesc}}</td>
I cannot get the required value.
The output display should be "g1".
javascript angular angular6
1
As per your screenshot,nas.assignmentAudit
points to an array, so it should be{nas.assignmentAudit[0].auditorGroup.groupDesc
– Robby Cornelissen
Nov 12 '18 at 5:21
1
This will work for you nas.assignmentAudit[0].auditorGroup.groupDesc
– Paresh Gami
Nov 12 '18 at 5:21
run Inner loop.
– Najam us saqib
Nov 12 '18 at 5:22
add a comment |
I have the JSON of single object coming as:
I achieved this data by calling the API in component.ts
file which is as follows
/* for auditgorup selecitonm */
this.http.get('http://localhost:8080/api/selections/getAllAuditGroupSelections')
.subscribe((datas: any) => {
this.auditSelection = datas;
console.log(this.auditSelection);
// You'll have to wait that changeDetection occurs and projects data into
// the HTML template, you can ask Angular to that for you ;-)
this.chRef1.detectChanges();
// Now you can use jQuery DataTables :
const tables: any = $('#nepal');
this.dataTable = tables.DataTable();
});
The view is as follows
<table id="nepal" class="table table-bodered">
<thead>
<tr>
<th>Selection No</th>
<th>SelectionDate</th>
<th>SelectedBy</th>
<th>PanEximNumber</th>
<th>Name</th>
<th>Address</th>
<th>PhoneNumber</th>
<th>SelectionType</th>
<th>Group Desc</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let nas of auditSelection">
<td>{{nas.selectionId}}</td>
<td>{{nas.selectionDate}}</td>
<td>{{nas.selectedBy}}</td>
<td>{{nas.panEximNumber}}</td>
<td>{{nas.name}}</td>
<td>{{nas.address}}</td>
<td>{{nas.phoneNumber}}</td>
<td>{{nas.selectionType}}</td>
<td>{{nas.assignmentAudit.auditorGroup.groupDesc}}</td>
</tr>
</tbody>
</table>
At this last line of <td>{{nas.assignmentAudit.auditorGroup.groupDesc}}</td>
I cannot get the required value.
The output display should be "g1".
javascript angular angular6
I have the JSON of single object coming as:
I achieved this data by calling the API in component.ts
file which is as follows
/* for auditgorup selecitonm */
this.http.get('http://localhost:8080/api/selections/getAllAuditGroupSelections')
.subscribe((datas: any) => {
this.auditSelection = datas;
console.log(this.auditSelection);
// You'll have to wait that changeDetection occurs and projects data into
// the HTML template, you can ask Angular to that for you ;-)
this.chRef1.detectChanges();
// Now you can use jQuery DataTables :
const tables: any = $('#nepal');
this.dataTable = tables.DataTable();
});
The view is as follows
<table id="nepal" class="table table-bodered">
<thead>
<tr>
<th>Selection No</th>
<th>SelectionDate</th>
<th>SelectedBy</th>
<th>PanEximNumber</th>
<th>Name</th>
<th>Address</th>
<th>PhoneNumber</th>
<th>SelectionType</th>
<th>Group Desc</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let nas of auditSelection">
<td>{{nas.selectionId}}</td>
<td>{{nas.selectionDate}}</td>
<td>{{nas.selectedBy}}</td>
<td>{{nas.panEximNumber}}</td>
<td>{{nas.name}}</td>
<td>{{nas.address}}</td>
<td>{{nas.phoneNumber}}</td>
<td>{{nas.selectionType}}</td>
<td>{{nas.assignmentAudit.auditorGroup.groupDesc}}</td>
</tr>
</tbody>
</table>
At this last line of <td>{{nas.assignmentAudit.auditorGroup.groupDesc}}</td>
I cannot get the required value.
The output display should be "g1".
javascript angular angular6
javascript angular angular6
edited Nov 12 '18 at 9:28
Samuel J Mathew
3,46912228
3,46912228
asked Nov 12 '18 at 5:18
ashwin karki
1949
1949
1
As per your screenshot,nas.assignmentAudit
points to an array, so it should be{nas.assignmentAudit[0].auditorGroup.groupDesc
– Robby Cornelissen
Nov 12 '18 at 5:21
1
This will work for you nas.assignmentAudit[0].auditorGroup.groupDesc
– Paresh Gami
Nov 12 '18 at 5:21
run Inner loop.
– Najam us saqib
Nov 12 '18 at 5:22
add a comment |
1
As per your screenshot,nas.assignmentAudit
points to an array, so it should be{nas.assignmentAudit[0].auditorGroup.groupDesc
– Robby Cornelissen
Nov 12 '18 at 5:21
1
This will work for you nas.assignmentAudit[0].auditorGroup.groupDesc
– Paresh Gami
Nov 12 '18 at 5:21
run Inner loop.
– Najam us saqib
Nov 12 '18 at 5:22
1
1
As per your screenshot,
nas.assignmentAudit
points to an array, so it should be {nas.assignmentAudit[0].auditorGroup.groupDesc
– Robby Cornelissen
Nov 12 '18 at 5:21
As per your screenshot,
nas.assignmentAudit
points to an array, so it should be {nas.assignmentAudit[0].auditorGroup.groupDesc
– Robby Cornelissen
Nov 12 '18 at 5:21
1
1
This will work for you nas.assignmentAudit[0].auditorGroup.groupDesc
– Paresh Gami
Nov 12 '18 at 5:21
This will work for you nas.assignmentAudit[0].auditorGroup.groupDesc
– Paresh Gami
Nov 12 '18 at 5:21
run Inner loop.
– Najam us saqib
Nov 12 '18 at 5:22
run Inner loop.
– Najam us saqib
Nov 12 '18 at 5:22
add a comment |
4 Answers
4
active
oldest
votes
I am unable to comment, so adding it over here. assignmentAudit is an array, so try accessing using index
for you can run inner loop.
– Najam us saqib
Nov 12 '18 at 5:23
add a comment |
As per the analysis of the JSON structure the assignmentAudit
is an array
so you can only access it with the index positions.
If you are sure the assignmentAudit
is an array with single value then you can use
<td>
{{nas.assignmentAudit[0].auditorGroup.groupDesc}}
</td>
If assignmentAudit
has multiple values and is not deterministic you can try
<td>
<span *ngFor="let assignmentAudit of nas.assignmentAudit">
{{assignmentAudit.auditorGroup.groupDesc}}
</span>
</td>
add a comment |
nas.assignmentAudit[0].auditorGroup.groupDesc
That would work. The section you are trying to access is an array. So picking the first index would then make it defined
add a comment |
groupDesc
is insideauditorGroup
loop so you cannot do like to get value inside loop. Try like that.
<!-- Angular -->
<ul>
<li *ngFor="let item of nas.assignmentAudit.auditorGroup;">
</li>
</ul>
or <td>{{nas.assignmentAudit.auditorGroup[0].groupDesc}}</td>
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53256308%2ferror-in-while-looping-in-ngfor-in-angular%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
I am unable to comment, so adding it over here. assignmentAudit is an array, so try accessing using index
for you can run inner loop.
– Najam us saqib
Nov 12 '18 at 5:23
add a comment |
I am unable to comment, so adding it over here. assignmentAudit is an array, so try accessing using index
for you can run inner loop.
– Najam us saqib
Nov 12 '18 at 5:23
add a comment |
I am unable to comment, so adding it over here. assignmentAudit is an array, so try accessing using index
I am unable to comment, so adding it over here. assignmentAudit is an array, so try accessing using index
answered Nov 12 '18 at 5:22
Bharathkumar kamal
765
765
for you can run inner loop.
– Najam us saqib
Nov 12 '18 at 5:23
add a comment |
for you can run inner loop.
– Najam us saqib
Nov 12 '18 at 5:23
for you can run inner loop.
– Najam us saqib
Nov 12 '18 at 5:23
for you can run inner loop.
– Najam us saqib
Nov 12 '18 at 5:23
add a comment |
As per the analysis of the JSON structure the assignmentAudit
is an array
so you can only access it with the index positions.
If you are sure the assignmentAudit
is an array with single value then you can use
<td>
{{nas.assignmentAudit[0].auditorGroup.groupDesc}}
</td>
If assignmentAudit
has multiple values and is not deterministic you can try
<td>
<span *ngFor="let assignmentAudit of nas.assignmentAudit">
{{assignmentAudit.auditorGroup.groupDesc}}
</span>
</td>
add a comment |
As per the analysis of the JSON structure the assignmentAudit
is an array
so you can only access it with the index positions.
If you are sure the assignmentAudit
is an array with single value then you can use
<td>
{{nas.assignmentAudit[0].auditorGroup.groupDesc}}
</td>
If assignmentAudit
has multiple values and is not deterministic you can try
<td>
<span *ngFor="let assignmentAudit of nas.assignmentAudit">
{{assignmentAudit.auditorGroup.groupDesc}}
</span>
</td>
add a comment |
As per the analysis of the JSON structure the assignmentAudit
is an array
so you can only access it with the index positions.
If you are sure the assignmentAudit
is an array with single value then you can use
<td>
{{nas.assignmentAudit[0].auditorGroup.groupDesc}}
</td>
If assignmentAudit
has multiple values and is not deterministic you can try
<td>
<span *ngFor="let assignmentAudit of nas.assignmentAudit">
{{assignmentAudit.auditorGroup.groupDesc}}
</span>
</td>
As per the analysis of the JSON structure the assignmentAudit
is an array
so you can only access it with the index positions.
If you are sure the assignmentAudit
is an array with single value then you can use
<td>
{{nas.assignmentAudit[0].auditorGroup.groupDesc}}
</td>
If assignmentAudit
has multiple values and is not deterministic you can try
<td>
<span *ngFor="let assignmentAudit of nas.assignmentAudit">
{{assignmentAudit.auditorGroup.groupDesc}}
</span>
</td>
edited Nov 12 '18 at 5:30
answered Nov 12 '18 at 5:24
Samuel J Mathew
3,46912228
3,46912228
add a comment |
add a comment |
nas.assignmentAudit[0].auditorGroup.groupDesc
That would work. The section you are trying to access is an array. So picking the first index would then make it defined
add a comment |
nas.assignmentAudit[0].auditorGroup.groupDesc
That would work. The section you are trying to access is an array. So picking the first index would then make it defined
add a comment |
nas.assignmentAudit[0].auditorGroup.groupDesc
That would work. The section you are trying to access is an array. So picking the first index would then make it defined
nas.assignmentAudit[0].auditorGroup.groupDesc
That would work. The section you are trying to access is an array. So picking the first index would then make it defined
answered Nov 12 '18 at 5:25
Toby Okeke
31518
31518
add a comment |
add a comment |
groupDesc
is insideauditorGroup
loop so you cannot do like to get value inside loop. Try like that.
<!-- Angular -->
<ul>
<li *ngFor="let item of nas.assignmentAudit.auditorGroup;">
</li>
</ul>
or <td>{{nas.assignmentAudit.auditorGroup[0].groupDesc}}</td>
add a comment |
groupDesc
is insideauditorGroup
loop so you cannot do like to get value inside loop. Try like that.
<!-- Angular -->
<ul>
<li *ngFor="let item of nas.assignmentAudit.auditorGroup;">
</li>
</ul>
or <td>{{nas.assignmentAudit.auditorGroup[0].groupDesc}}</td>
add a comment |
groupDesc
is insideauditorGroup
loop so you cannot do like to get value inside loop. Try like that.
<!-- Angular -->
<ul>
<li *ngFor="let item of nas.assignmentAudit.auditorGroup;">
</li>
</ul>
or <td>{{nas.assignmentAudit.auditorGroup[0].groupDesc}}</td>
groupDesc
is insideauditorGroup
loop so you cannot do like to get value inside loop. Try like that.
<!-- Angular -->
<ul>
<li *ngFor="let item of nas.assignmentAudit.auditorGroup;">
</li>
</ul>
or <td>{{nas.assignmentAudit.auditorGroup[0].groupDesc}}</td>
answered Nov 12 '18 at 5:24
PPShein
4,5542380139
4,5542380139
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53256308%2ferror-in-while-looping-in-ngfor-in-angular%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
As per your screenshot,
nas.assignmentAudit
points to an array, so it should be{nas.assignmentAudit[0].auditorGroup.groupDesc
– Robby Cornelissen
Nov 12 '18 at 5:21
1
This will work for you nas.assignmentAudit[0].auditorGroup.groupDesc
– Paresh Gami
Nov 12 '18 at 5:21
run Inner loop.
– Najam us saqib
Nov 12 '18 at 5:22