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.





ngFor works over an array. Check if Question is an arrya
– Sajeetharan
Aug 25 at 8:06





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.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)