Maybe a easy question, but I couldn't find a example for this.
This is my HttpClient call
getItems(dataSourceUrl: string, bindKey: string, bindValue: string): Observable<SelectItem[]> {
return this.httpClient.get<Array<any>>(dataSourceUrl);
}
I want to map the list result to SelectItem[] based on bindKey and bindValue. How do I do that?
I tried something like this
return this.httpClient.get<Array<any>>(dataSourceUrl).pipe(map(x=> { return { label: data.bindKey, value: data.bindValue } }));
Interface
export interface SelectItem {
label: string;
value: any;
}
Example of two different api responses
1.
{key:'Istanbul', value: 'Test' }
{key:'London', value: 'Test' }
bindKey will be key
bindValue will be value
2.
{name:'Istanbul', id: 'Test' }
{name:'Istanbul', id: 'Test' }
bindKey will be id
bindValue will be name
SelectItemand what is the API response. In the code shared, Also, I cant seedataobject which you are using asdata.bindKey. Am i missing something ? Best thing would be to shareAPIresponse and expected response after applyingmap