Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays. Angular
Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays. Angular
html
<div class="py-4" *ngFor="let data of Question; let i = index">
json
</div>
component.ts
ngOnInit()
this.showQuestion();
Question: any ;
showQuestion()
const Entity = new TaskViewEntity(someParameter, 'QuestionDetails');
this.serviceParameter.TaskApi(Entity.requestFormat).subscribe(res =>
if (res['result'].questionDetails !== undefined)
const arr = res['result'].questionDetails.questions;
this.Question = arr.map(item =>
return
'counter': 1,
'answer': item.answer,
'approveFlag': item.approveFlag,
'options': item.options,
'question': item.question,
'questionId': item.questionId,
'questionType': item.questionType,
'subQuestion': item.subQuestion
;
);
);
service.ts
public TaskApi = (data) =>
const url = 'URL';
return this.http.post(url, data);
Json
"questions": [
"questionId": 44,
"question": "abc",
"questionType": "checkbox",
,
"questionId": 44,
"question": "abc",
"questionType": "checkbox",
,
"questionId": 44,
"question": "abc",
"questionType": "checkbox",
,
]
After using console.log(this.Question), i get this result
(3) […, …, …]
0: counter: 1, answer: "", approveFlag: true, options: …, question: "Please confirm the address of the property is", …
1: counter: 1, answer: "", approveFlag: true, options: …, question: "Please confirm the name of the seller?", …
2: counter: 1, answer: "", approveFlag: true, options: …, question: "Please confirm the number of sellers/partners?", …
The above mentioned code not working it shows the error in my console which is : Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays. Angular. I am not able to access questions.
question is an array.
– angular_nerd
Aug 25 at 8:08
It is an array like this => question: [..., ..., ...]
– angular_nerd
Aug 25 at 8:09
post the JSON to check
– Sajeetharan
Aug 25 at 8:09
I have posted my json after editing my question. Please check
– angular_nerd
Aug 25 at 8:14
1 Answer
1
I think you have not initialised the array questions in the first place , you are initialising it in subscribe , so until then it is uninitialised , can you try doing : Question: any = ;
Question: any = ;
I have done that
– angular_nerd
Aug 25 at 9:15
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.
ngFor works over an array. Check if Question is an arrya
– Sajeetharan
Aug 25 at 8:06