Error trying to diff '[object object]'. Only arrays and iterables are allowed in angular

7,584 views
Skip to first unread message

Akshay malvankar

unread,
Oct 2, 2019, 5:56:46 AM10/2/19
to Angular and AngularJS discussion
i create one PHP web API,where i get response from API ok, but result not display on view

following is response which i get from Web API

Hide   Copy Code
{
            "status": true,
            "data": {
                "statistics": [
                    {
                        "State": "Karnataka",
                        "SurveyorName": "Keval Kakdiya",
                        "NoOfInt": "2",
                        "SampleReceived": "2",
                        "CancelledEntries": "0",
                        "Approved": "1",
                        "DisApproved": "1"
                    },
                    {
                        "State": "MAHARASHTRA",
                        "SurveyorName": "Keval Kakdiya",
                        "NoOfInt": "0",
                        "SampleReceived": "0",
                        "CancelledEntries": "1",
                        "Approved": "0",
                        "DisApproved": "0"
                    }
                ],
            }
        }


in angular i create one array and pass above response to that array

// following is angular code

Hide   Copy Code
result:any =[];


Hide   Copy Code
this.result = response;


// following is html code

Hide   Copy Code
<tr *ngFor="let report of result.data.statistics;">
                         <td> {{report.SurveyorName}}            </td>
                         <td> {{report.NoOfInt}}    </td>
                         <td> {{report.CancelledEntries}}    </td>
                         <td> {{report.Approved}}    </td>
                         <td> {{report.DisApproved}} </td>
                         <td> {{report.State}}</td>
                         <td> <button class="btn-dark" type='button'> View </button></td>
                      </tr>

Sander Elias

unread,
Oct 3, 2019, 1:44:38 AM10/3/19
to Angular and AngularJS discussion
Hi Akshay,

There seems no error in the code you are showing here. My guess would be that there is something off in the code you are not showing.
Show us the http.get request and the surroundings of `this.result=response`

Regards
Sander
Reply all
Reply to author
Forward
0 new messages