I am getting the following response from a service, which includes form definition in json schema format.
Now I want to iterate this response in angular component.
So I have fetched all the schema elements like this in one Formdata variable.
res['tabs'].forEach(element => {
this.tablist.push(element);
});
this.tablist.forEach(element => {
this.FormData[element] = res['com'][element]['schema'];
this.FormValueData[element] = res['com'][element]['data'];
this.FetchValueParam[element] = res['com'][element]['data'];
});
Now I want to access the value of Formdata in side a view and I have wrote following code for it.
<form>
<div *ngFor='let input1 of FormData[element]['properties']'>
<label [for]='input1.type'> input1.title</label>
<input type='input1.type' [name]='input1.title'
[placeholder]='something'>
<br>
</div>
<br><br>
<button type="submit"> Submit </button>
</form>
But I am not able to access this it as an array as it is a json object. I have tried Array.of() and Array.from() but it is not working with the following error. How to iterate through the json and create form fields?
Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays
Update: When I am using a dummy json object like this. I am getting desired result. So what I am getting is , there is some serious mismatch between type expected by ngFor and type I am supplying as a json object.
this.inputfield=
[{type:'email',name:'email',value:'',placeholder:"your email here"},
{type:'email',name:'email',value:'',placeholder:'your email
here'},{type:'email',name:'email',value:'',placeholder:'your
email here'},
{type:'email',name:'email',value:'',placeholder:'your email
here'},{type:'email',name:'email',value:'',placeholder:'your
email here'},
{type:'email',name:'email',value:'',placeholder:'your email
here'},{type:'email',name:'email',value:'',placeholder:'your
email here'},
{type:'email',name:'email',value:'',placeholder:'your email
here'},{type:'email',name:'email',value:'',placeholder:'your
email
here'}{type:'email',name:'email',value:'',placeholder:'your
email here'}];
When I checked the difference between both of them in json schema validator, The Former I showed in console is coming as object but the above is coming is array.
So Either I send array not object or I create one array or class based on above json schema at run time. What is better to do?