I've got an angular component that calls via http to an API to populate a select list. The property on this component looks like this:
searchKeys: SelectItem[];
And the function that gets the data onInit that works just fine:
private GetSearchKeyList() {
this._httpService.get('/api/List/Key')
.map(result => result.json())
.subscribe(list => {
this.searchKeys = list.map(item => {
return { label: item.text, value: item.value };
});
});
}
Now, I'd like to turn it into something more generic that I can use for other properties, so something like this:
this.LoadListValues('/api/List/Key', this.searchKeys);
private LoadListValues(apiEndpoint: string, projectTo: SelectItem[]) {
this._httpService.get(apiEndpoint)
.map(result => result.json())
.subscribe(list => {
projectTo = list.map(item => {
return { label: item.text, value: item.value };
});
});
}
But this doesn't seem to work, where I'm passing 'projectTo' as a reference to the property on my component, it's never populated with values.
What am I missing here?