I am new to the angular formly .My requirement is to place the cities (coming from the backend )in dropdown but I have tried but I am unable to do this.
.service.ts
getcitiNames(): Observable<any> {
return this.http.get(this.baseUrl + '/api/data/xxx/city/getcity');
}
from the above API I have to fetch the dropdown elements and place it in the select dropdown like
.ts
{
key: 'Select',
type: 'select',
className: 'select-stlyes',
templateOptions: {
label: 'Status',
options: [
{ value: 1, label: 'data1' },
{ value: 2, label: 'data2' },
{ value: 3, label: 'data3' }
],
},
},
Can anyone help me regarding this
Let's assume your API is returning a
string[]
which has the values to be populated in dropdown. From your angular component you must have theFormlyFields[]
constructed to prepare the form.I would suggest you to maintain a unique
key
for eachfield
object that you push to thefields[]
. This will help you in identifying which element is which and populate data accordingly.After you have subscribed to the
API
which has the values for dropdown,