Error in while looping in *ngFor in angular












0














I have the JSON of single object coming as:



JSON Structure



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".










share|improve this question




















  • 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


















0














I have the JSON of single object coming as:



JSON Structure



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".










share|improve this question




















  • 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
















0












0








0







I have the JSON of single object coming as:



JSON Structure



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".










share|improve this question















I have the JSON of single object coming as:



JSON Structure



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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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
















  • 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














4 Answers
4






active

oldest

votes


















2














I am unable to comment, so adding it over here. assignmentAudit is an array, so try accessing using index






share|improve this answer





















  • for you can run inner loop.
    – Najam us saqib
    Nov 12 '18 at 5:23



















2














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>





share|improve this answer































    1














    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






    share|improve this answer





























      0














      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>






      share|improve this answer





















        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
        });


        }
        });














        draft saved

        draft discarded


















        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









        2














        I am unable to comment, so adding it over here. assignmentAudit is an array, so try accessing using index






        share|improve this answer





















        • for you can run inner loop.
          – Najam us saqib
          Nov 12 '18 at 5:23
















        2














        I am unable to comment, so adding it over here. assignmentAudit is an array, so try accessing using index






        share|improve this answer





















        • for you can run inner loop.
          – Najam us saqib
          Nov 12 '18 at 5:23














        2












        2








        2






        I am unable to comment, so adding it over here. assignmentAudit is an array, so try accessing using index






        share|improve this answer












        I am unable to comment, so adding it over here. assignmentAudit is an array, so try accessing using index







        share|improve this answer












        share|improve this answer



        share|improve this answer










        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


















        • 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













        2














        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>





        share|improve this answer




























          2














          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>





          share|improve this answer


























            2












            2








            2






            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>





            share|improve this answer














            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>






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 12 '18 at 5:30

























            answered Nov 12 '18 at 5:24









            Samuel J Mathew

            3,46912228




            3,46912228























                1














                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






                share|improve this answer


























                  1














                  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






                  share|improve this answer
























                    1












                    1








                    1






                    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






                    share|improve this answer












                    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







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Nov 12 '18 at 5:25









                    Toby Okeke

                    31518




                    31518























                        0














                        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>






                        share|improve this answer


























                          0














                          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>






                          share|improve this answer
























                            0












                            0








                            0






                            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>






                            share|improve this answer












                            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>







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Nov 12 '18 at 5:24









                            PPShein

                            4,5542380139




                            4,5542380139






























                                draft saved

                                draft discarded




















































                                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.




                                draft saved


                                draft discarded














                                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





















































                                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







                                Popular posts from this blog

                                Full-time equivalent

                                さくらももこ

                                13 indicted, 8 arrested in Calif. drug cartel investigation