I recently integrated the ng-select component into my project to enable an autocomplete feature in a select dropdown.
However, I encountered issues when trying to populate the options of this select from a JSON file!
Here is the part that works:
prodFilterDescr: Array<IOption> = [
{label: 'Belgium', value: 'Belgium'},
{label: 'Luxembourg', value: 'Luxembourg'},
{label: 'Netherlands', value: 'Netherlands'}
];
Html:
...<ng-select
[options]="prodFilterDescr"
placeholder="Prodotto"
>
</ng-select>...
The following part doesn't work (within the constructor):
this.http.get('app/json/filtriProdotti.json')
.subscribe(res => this.filters = res.json());
var filter = [];
this.filters.forEach(function(item){
filter.push(item.tipoProdottoId)
})
console.log(filter)
let typeProdFilter: Array<IOption> = filter;
console.log(typeProdFilter)
Html:
<ng-select
[options]="typeProdFilter"
placeholder="Tipo prodotto"
>
</ng-select>
I'm having trouble getting my "options" to successfully read the data from my JSON file. How can I resolve this issue?