I am making angular 6 application, where i am making a angular dynamic form in which the data comes as dynamic from JSON.
JSON:
jsonData: any = [
{
"elementType": "textbox",
"class": "col-12 col-md-4 col-sm-12",
"key": "project_name",
"label": "Project Name",
"type": "text",
"value": "",
"required": false,
"minlength": 3,
"maxlength": 20,
"order": 1
},
{
"elementType": "textbox",
"class": "col-12 col-md-4 col-sm-12",
"key": "project_desc",
"label": "Project Description",
"type": "text",
"value": "",
"required": true,
"order": 2
},
{
"elementType": "dropdown",
"key": 'project',
"label": 'Project Rating',
"options": [
{ "key": 'average', "value": 'Average' },
{ "key": 'good', "value": 'Good' },
{ "key": 'great', "value": 'Great' }
],
"order": 3
}
];
Here in dropdown, i would like to have the options
array from the service call..
As of now you could able to see that i have hard coded it in options..
Service in dynamic-form.component.ts
:
getDropdownValues(url,token) {
this.service.get(url,token).subscribe(res => {
console.log(res.data);
});
}
res.data returns the following,
{
data: [
{ "key": 'average', "value": 'Average' },
{ "key": 'good', "value": 'Good' },
{ "key": 'great', "value": 'Great' }
]
}
This data array is going to be the options
in JSON..
As of now i have given the JSON inside .ts
file but later it will be a separate .json
file.
The working stackblitz: https://stackblitz.com/edit/angular-x4a5b6-ng8m4z
Kindly help me to place the data comes from service (res.data) to the dropdown options
inside JSON..